﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Diagnostics;
using System.Drawing;
using System.IO;
using netDxf;
using netDxf.Blocks;
using netDxf.Collections;
using netDxf.Entities;
using netDxf.Header;
using netDxf.Objects;
using netDxf.Tables;
using netDxf.Units;
using Attribute = netDxf.Entities.Attribute;
using Image = netDxf.Entities.Image;
using Point = netDxf.Entities.Point;
using Trace = netDxf.Entities.Trace;
using System.Windows.Media.Imaging;

namespace TestDxfDocument
{
    //
    class RectangularShank
    {
        private static readonly double pi = Math.PI;
        //刀片法后角及其对应的字母
        private static readonly Dictionary<double, string> alphan_p = new Dictionary<double, string>() {
            {3 * pi /180,"A"},
            {5 * pi /180,"B"},
            {7 * pi /180,"C"},
            {15 * pi /180,"D"},
            {20 * pi /180,"E"},
            {25 * pi /180,"F"},
            {30 * pi /180,"G"},
            {0 * pi /180,"N"},
            {11 * pi /180,"P"},
        };

        private static Dictionary<string, double> style_dic = new Dictionary<string, double>();
        static RectangularShank()
        {
            //刀杆头部形状
            style_dic.Add("A", 90);
            style_dic.Add("B", 75);
            style_dic.Add("F", 90);
            style_dic.Add("H", 107);
            style_dic.Add("J", 93);
            style_dic.Add("R", 75);
            style_dic.Add("S", 45);
            style_dic.Add("V", 72.5);
            //刀片形状
        }

        //删除了未用到的图形
        //注释优化

        //A型刀头 横大跨
        public static void StyleA_InsertC(Dictionary<string, Object> data)
        {
            DxfDocument dxf = new DxfDocument();
            Layer contour = new Layer("contour") { Color = AciColor.Cyan };    //1,轮廓层
            Layer cutting = new Layer("cutting") { Color = AciColor.Red };    //切削层
            string path = Convert.ToString(data["path"]);
            //参数名称取自ISO 5610-2
            double a = 1.6;
            double b = 8;
            double l1 = 70;
            double l2 = 12;
            double f = 8.5;
            double insertAngle = 80 * pi / 180;
            double l3 = 6.4;
            double repsilon = 0.4;
            double h2 = 8;
            double h1 = 8;
            double s = 2.38;
            double alphan = 7 * pi / 180;
            double cutagl = 90 * pi / 180;
            double gamao = 0;
            double lambdas = 0;
            #region data中取值
            try
            {
                if (data["re"] != null)
                    repsilon = Convert.ToDouble(data["re"]);
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["lams"] != null)
                    lambdas = Convert.ToDouble(data["lams"]) * pi / 180;
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["gamo"] != null)
                    gamao = Convert.ToDouble(data["gamo"]) * pi / 180;
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["lfa"] != null)
                    a = Convert.ToDouble(data["lfa"]);
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["b"] != null)
                    b = Convert.ToDouble(data["b"]);
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["s"] != null)
                    s = Convert.ToDouble(data["s"]);
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["lf"] != null)
                    l1 = Convert.ToDouble(data["lf"]);
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["lh"] != null)
                    l2 = Convert.ToDouble(data["lh"]);
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["wf"] != null)
                    f = Convert.ToDouble(data["wf"]);
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["h"] != null)
                    h2 = Convert.ToDouble(data["h"]);
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["hf"] != null)
                    h1 = Convert.ToDouble(data["hf"]);
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["epsr"] != null)
                    insertAngle = Convert.ToDouble(data["epsr"]) * pi / 180;
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["kapr"] != null)
                    cutagl = Convert.ToDouble(data["kapr"]) * pi / 180;
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["an"] != null)
                    alphan = Convert.ToDouble(data["an"]) * pi / 180;
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["l"] != null)
                    l3 = Convert.ToDouble(data["l"]);
            }
            catch (KeyNotFoundException) { }
            #endregion
            //线性变换
            Vector2 zero = new Vector2(0, 0);
            double kscale;
            if (l1 >= 120)
                kscale = 1.5;
            else
                kscale = 2;
            double rotate4T = 0 * pi / 180;
            double ix = fun.Polar(zero, rotate4T, kscale).X;
            double iy = fun.Polar(zero, rotate4T, kscale).Y;
            double jx = fun.Polar(zero, rotate4T + pi / 2, kscale).X;
            double jy = fun.Polar(zero, rotate4T + pi / 2, kscale).Y;
            Matrix3 trans = new Matrix3(
                ix, jx, 0,
                iy, jy, 0,
                0, 0, 1
                );
            double lineWidth = 1;
            ///if一个实体是由线性变换后的实体通过某种方法得到的，该实体也参与了线性变换，不再对其进行线性变换
            Vector2 oc1 = new Vector2(0, 0);
            Vector2 oc2 = new Vector2(oc1.X, oc1.Y + b);
            Vector2 oc10 = new Vector2(oc2.X - l1 + l2, oc1.Y);
            Vector2 oc3 = new Vector2(oc10.X, oc2.Y);
            Vector2 oc4 = new Vector2(oc3.X - 2, oc3.Y);
            Vector2 oc9 = new Vector2(oc10.X - 1, oc10.Y);

            Vector2 c1 = Pus.LinearTrans(trans, oc1);
            Vector2 c2 = Pus.LinearTrans(trans, oc2);
            Vector2 c10 = Pus.LinearTrans(trans, oc10);
            Vector2 c3 = Pus.LinearTrans(trans, oc3);
            Vector2 c4 = Pus.LinearTrans(trans, oc4);
            Vector2 c9 = Pus.LinearTrans(trans, oc9);
            ///刀片部分
            //k点位置参考lc模型k点与i4关系文件"横向进给，>90" 考虑到90°在临界位置，判断使用哪个k点方案(根据ISO 5610-1)
            Vector2 ok = new Vector2(oc1.X - l1, oc2.Y - f);
            Vector2 k = Pus.LinearTrans(trans, ok);
            Vector2 oi4;
            if (cutagl * 180 / pi > 90)
            {
                Vector2 kp = fun.Polar(ok, -pi / 2, repsilon / Math.Tan((pi - cutagl) / 2) - repsilon);
                oi4 = fun.Polar(kp, -pi / 2 - (pi - cutagl), repsilon / Math.Tan(insertAngle / 2) - repsilon / Math.Tan((pi - cutagl) / 2));
            }
            else
            {
                oi4 = fun.Polar(ok, cutagl - pi, repsilon * (1 / Math.Tan(insertAngle / 2) - 1 / Math.Tan((pi - cutagl) / 2)));
            }
            Vector2[] oipoints = Pus.DiamondPoints(oi4, l3, insertAngle, true, cutagl);
            Vector2 oi1 = oipoints[1];
            Vector2 oi2 = oipoints[2];
            Vector2 oi3 = oipoints[3];
            Vector2 i4 = Pus.LinearTrans(trans, oi4);
            Vector2 i1 = Pus.LinearTrans(trans, oi1);
            Vector2 i2 = Pus.LinearTrans(trans, oi2);
            Vector2 i3 = Pus.LinearTrans(trans, oi3);
            LwPolyline insertContour = Pus.AddPointsToLwPolyLine(i4, i1, i2, i3);
            insertContour.IsClosed = true;
            //添加圆弧,这些圆弧的位置是已经参与了线性变换的圆弧，大小没有
            Pus.AglToArc(insertContour, repsilon * kscale);
            ///偏移部分
            double theOffset = s * Math.Tan(alphan);
            Vector2[] oiipoints = Pus.OffsetPoints(theOffset, oipoints);
            Vector2 oii1 = oiipoints[1];
            Vector2 oii2 = oiipoints[2];
            Vector2 oii3 = oiipoints[3];
            Vector2 oii4 = oiipoints[0];
            Vector2 ii1 = Pus.LinearTrans(trans, oii1);
            Vector2 ii2 = Pus.LinearTrans(trans, oii2);
            Vector2 ii3 = Pus.LinearTrans(trans, oii3);
            Vector2 ii4 = Pus.LinearTrans(trans, oii4);
            ///交点u1，u2
            //u1，u2由线性变换后的实体相交得到，相当于参与了线性变换
            Vector2 u1;
            Vector2 u2;
            if (alphan == 0)
            {
                u1 = insertContour.Vertexes[2].Position;
                u2 = insertContour.Vertexes[7].Position;
            }
            else
            {
                Arc iarc2 = Pus.GetArcFromPline(insertContour, 2);
                List<Vector2> u1s = Pus.LineXArc(iarc2, ii1, ii4);
                if (u1s == null || u1s.Count == 0)
                    u1 = fun.Inters(ii1, ii4, i1, i2);
                else
                    u1 = u1s[0];

                Arc iarc4 = Pus.GetArcFromPline(insertContour, 4);
                List<Vector2> u2s = Pus.LineXArc(iarc4, ii3, ii4);
                if (u2s == null || u2s.Count == 0)
                    u2 = fun.Inters(i2, i3, ii3, ii4);
                else
                    u2 = u2s[0];
            }

            ///交点c11，c12
            Vector2 oc5 = new Vector2(oi3.X + kscale, oc4.Y);
            Vector2 oc8 = new Vector2(Pus.KPoint(oi1, oc9, 0.3).X, oc9.Y);

            Vector2 c5 = Pus.LinearTrans(trans, oc5);
            Vector2 n6p = fun.Inters(c2, c5, ii4, ii3);
            Vector2 c6 = Pus.KPoint(u2, n6p, 0.7);
            Vector2 oc6 = Pus.LinearTrans(trans.Inverse(), c6);
            Vector2 c8 = Pus.LinearTrans(trans, oc8);
            ///绘制main视图
            LwPolyline mcontour1 = Pus.AddPointsToLwPolyLine(c1, c2, c3, c4, c5, c6, u2);
            //fun.PolyFill(dxf, mcontour1, lineWidth, contour);
            fun.drawBLine(dxf, Pus.GetV2ArrayFromLwPolyline(mcontour1), lineWidth, contour);
            //LwPolyline mcontour2 = Pus.AddPointsToLwPolyLine(Pus.KPoint(i2,i3,0.5), i2, Pus.KPoint(i2,i1,0.5));
            //fun.PolyFill(dxf, mcontour2, lineWidth, contour);
            LwPolyline mcontour3 = Pus.AddPointsToLwPolyLine(u1, c8, c9, c10, c1);
            //fun.PolyFill(dxf, mcontour3, lineWidth, contour);
            fun.drawBLine(dxf, Pus.GetV2ArrayFromLwPolyline(mcontour3), lineWidth, contour);


            fun.PolyFill(dxf, insertContour, lineWidth, cutting);
            fun.drawBLine(dxf, new Vector2[] { c10, c3 }, lineWidth, contour);
            fun.drawBLine(dxf, new Vector2[] { c9, c4 }, lineWidth, contour);
            ///main视图标注
            DimensionStyle dimensionStyle = fun.CreateDimStyle();

            dimensionStyle.ArrowSize = 0.2;
            dimensionStyle.DimArrow1 = DimensionArrowhead.Closedfilled;
            dimensionStyle.DimArrow2 = DimensionArrowhead.Closedfilled;
            dimensionStyle.TextHeight = kscale;
            dimensionStyle.TextOffset = kscale / 2;
            double offset = 7 * kscale;
            LinearDimension dim_l1 = new LinearDimension(new Line(k, c1), -offset, Vector2.Angle(c10, c1) * 180 / pi, dimensionStyle);
            fun.dxflinedim(dxf, dim_l1, l1);
            LinearDimension dim_l2 = new LinearDimension(new Line(k, c10), -offset * 0.5, Vector2.Angle(c10, c1) * 180 / pi, dimensionStyle);
            fun.dxflinedim(dxf, dim_l2, l2);
            LinearDimension dim_l3 = new LinearDimension(new Line(i3, i2), offset, Vector2.Angle(i3, i2) * 180 / pi, dimensionStyle);
            // dim_l3.UserText = l3.ToString().Substring(0, 4);
            //dxf.AddEntity(dim_l3);
            fun.dxflinedim(dxf, dim_l3, l3);
            LinearDimension dim_f = new LinearDimension(new Line(k, c5), offset, Vector2.Angle(c1, c2) * 180 / pi, dimensionStyle);
            fun.dxflinedim(dxf, dim_f, f);
            LinearDimension dim_b = new LinearDimension(new Line(c1, c2), -offset, Vector2.Angle(c1, c2) * 180 / pi, dimensionStyle);
            fun.dxflinedim(dxf, dim_b, b);
            Angular2LineDimension dim_cutAgl1 = new Angular2LineDimension(new Line(i4, i1), new Line(i4, fun.Polar(i4, Vector2.Angle(i4, i1) - cutagl, 1)), 2 * kscale, dimensionStyle);
            dim_cutAgl1.UserText = cutagl * 180 / pi + "°";
            dxf.AddEntity(dim_cutAgl1);
            //Angular2LineDimension dim_cutAgl2 = new Angular2LineDimension(new Line(i4, i3), new Line(i4, fun.Polar(i4, Vector2.Angle(i4, i3) + cutagl, 1)), 2 * kscale, dimensionStyle);
            //dim_cutAgl2.UserText = cutagl * 180 / pi + "°";
            //dxf.AddEntity(dim_cutAgl2);
            Angular2LineDimension dim_insertagl = new Angular2LineDimension(new Line(i4, i1), new Line(i4, i3), l3 / 2 * kscale, dimensionStyle);
            dim_insertagl.UserText = insertAngle * 180 / pi + "°";
            dxf.AddEntity(dim_insertagl);
            RadialDimension dim_repsilon = new RadialDimension(Pus.GetArcFromPline(insertContour, 1), Vector2.Angle(i3, i4) * 180 / pi - 30, 3 * kscale, dimensionStyle);
            dim_repsilon.UserText = "rε=" + Math.Round(repsilon / kscale, 2);
            dxf.AddEntity(dim_repsilon);

            ///lower视图
            Vector2 ol1 = new Vector2(oc1.X, oc1.Y - offset * 1.8);
            Vector2 ol2 = new Vector2(oc1.X, ol1.Y - h2);
            Vector2 ol3 = new Vector2(oc8.X, ol2.Y);
            Vector2 ol10 = new Vector2(oc10.X, ol1.Y);

            Vector2 nl1 = Pus.LinearTrans(trans, ol1);
            Vector2 nl2 = Pus.LinearTrans(trans, ol2);
            Vector2 nl3 = Pus.LinearTrans(trans, ol3);
            Vector2 nl10 = Pus.LinearTrans(trans, ol10);

            Vector2 oli4 = new Vector2(oi4.X, ol2.Y + h1);
            Vector2[] shankHead = Pus.Diamonds3d(oli4, gamao, lambdas, s, cutagl - pi / 2, 4, false, new Vector2[] {
            oi4,oi1,oi2,oi3,oii4,oii1,oii2,oii3,oc4,oc5,oc6,oc8,oc9});
            //oli4以新的为准
            oli4 = shankHead[0];
            Vector2 oli1 = shankHead[1];
            Vector2 oli2 = shankHead[2];
            Vector2 oli3 = shankHead[3];
            Vector2 olii4 = shankHead[4];
            Vector2 olii1 = shankHead[5];
            Vector2 olii2 = shankHead[6];
            Vector2 olii3 = shankHead[7];
            Vector2 ol4 = shankHead[8];
            Vector2 ol5 = shankHead[9];
            Vector2 ol6 = shankHead[10];
            Vector2 ol8 = shankHead[11];
            Vector2 ol9 = shankHead[12];
            Vector2 ol7 = new Vector2(olii4.X, ol3.Y);

            Vector2 nl7 = Pus.LinearTrans(trans, ol7);
            Vector2 li4 = Pus.LinearTrans(trans, oli4);
            Vector2 li1 = Pus.LinearTrans(trans, oli1);
            Vector2 li2 = Pus.LinearTrans(trans, oli2);
            Vector2 li3 = Pus.LinearTrans(trans, oli3);
            Vector2 lii4 = Pus.LinearTrans(trans, olii4);
            Vector2 lii1 = Pus.LinearTrans(trans, olii1);
            Vector2 lii2 = Pus.LinearTrans(trans, olii2);
            Vector2 lii3 = Pus.LinearTrans(trans, olii3);
            Vector2 nl4 = Pus.LinearTrans(trans, ol4);
            Vector2 nl5 = Pus.LinearTrans(trans, ol5);
            Vector2 nl6 = Pus.LinearTrans(trans, ol6);
            Vector2 nl8 = Pus.LinearTrans(trans, ol8);
            Vector2 nl9 = Pus.LinearTrans(trans, ol9);

            LwPolyline lcontour;
            if (gamao <= 0)
            {
                lcontour = Pus.AddPointsToLwPolyLine(nl1, nl2, nl3, nl7, lii4, lii1, li1, nl8, nl9, nl10);
                lcontour.IsClosed = true;
                fun.PolyFill(dxf, lcontour, lineWidth, contour);

                LwPolyline linsert = Pus.AddPointsToLwPolyLine(lii4, lii1, li1, li4);
                linsert.IsClosed = true;
                fun.PolyFill(dxf, linsert, lineWidth, cutting);
            }
            else
            {
                lcontour = Pus.AddPointsToLwPolyLine(nl1, nl2, nl3, nl7, lii4, lii1, li1, li2, li3, nl6, nl5, nl4, nl9, nl10);
                lcontour.IsClosed = true;
                fun.PolyFill(dxf, lcontour, lineWidth, contour);
                fun.drawBLine(dxf, new Vector2[] { li1, nl8, nl9 }, lineWidth, contour);
                fun.drawBLine(dxf, new Vector2[] { nl8, nl3 }, lineWidth, contour);

                LwPolyline lupperinsert = Pus.AddPointsToLwPolyLine(li4, li1, li2, li3);
                lupperinsert.IsClosed = true;
                fun.PolyFill(dxf, lupperinsert, lineWidth, cutting);
                fun.drawBLine(dxf, new Vector2[] { li4, lii4, lii1, li1 }, lineWidth, cutting);
            }
            //lowwer标注
            LinearDimension dim_h2 = new LinearDimension(new Line(nl1, nl2), offset, Pus.Degree(nl1, nl2), dimensionStyle);
            fun.dxflinedim(dxf, dim_h2, h2);
            LinearDimension dim_h1 = new LinearDimension(new Line(nl7, li4), offset, Pus.Degree(nl7, lii4), dimensionStyle);
            fun.dxflinedim(dxf, dim_h1, h1);
            if (lambdas == 0)
                Pus.NeedleDim(dxf, new Line(li4, fun.Polar(li4, Vector2.Angle(li4, li1) - 1 * pi / 180, 1)), new Line(li4, fun.Polar(li4, Vector2.Angle(nl3, nl7), 1)), offset, "0°", dimensionStyle);
            else
                Pus.NeedleDim(dxf, new Line(li4, li1), new Line(li4, fun.Polar(li4, Vector2.Angle(nl3, nl7), 1)), offset, lambdas * 180 / pi + "°", dimensionStyle);

            Vector2 oti4 = new Vector2(oi4.X - offset * 1.2, oi4.Y);
            Vector2[] leftview = Pus.Diamonds3d(oti4, gamao, lambdas, s, cutagl - pi / 2, 4, true,
               new Vector2[] { oi4, oi1, oi2, oi3, oii4, oii1, oii2, oii3, oc4, oc5, oc6, oc8, oc9 });
            oti4 = leftview[0];
            int i = 1;
            Vector2 oti1 = leftview[i++];
            Vector2 oti2 = leftview[i++];
            Vector2 oti3 = leftview[i++];
            Vector2 otii4 = leftview[i++];
            Vector2 otii1 = leftview[i++];
            Vector2 otii2 = leftview[i++];
            Vector2 otii3 = leftview[i++];
            Vector2 ot4 = leftview[i++];
            Vector2 ot5 = leftview[i++];
            Vector2 ot6 = leftview[i++];
            Vector2 ot8 = leftview[i++];
            Vector2 ot9 = leftview[i++];

            Vector2 ot3 = new Vector2(oti4.X - h1, otii4.Y);
            Vector2 ot1 = new Vector2(ot3.X, ot5.Y);
            Vector2 ot2 = new Vector2(ot3.X, ot6.Y);


            Vector2 t1 = Pus.LinearTrans(trans, ot1);
            Vector2 t2 = Pus.LinearTrans(trans, ot2);
            Vector2 t3 = Pus.LinearTrans(trans, ot3);
            Vector2 t4 = Pus.LinearTrans(trans, ot4);
            Vector2 t5 = Pus.LinearTrans(trans, ot5);
            Vector2 t6 = Pus.LinearTrans(trans, ot6);
            Vector2 t9 = Pus.LinearTrans(trans, ot9);
            Vector2 ti4 = Pus.LinearTrans(trans, oti4);
            Vector2 ti1 = Pus.LinearTrans(trans, oti1);
            Vector2 ti2 = Pus.LinearTrans(trans, oti2);
            Vector2 ti3 = Pus.LinearTrans(trans, oti3);
            Vector2 tii1 = Pus.LinearTrans(trans, otii1);
            Vector2 tii4 = Pus.LinearTrans(trans, otii4);
            Vector2 tii2 = Pus.LinearTrans(trans, otii2);
            Vector2 tii3 = Pus.LinearTrans(trans, otii3);

            LwPolyline tcontour;
            tcontour = Pus.AddPointsToLwPolyLine(t1, t2, t3, tii4, tii3, ti3, t6, t5);
            tcontour.IsClosed = true;
            fun.PolyFill(dxf, tcontour, lineWidth, contour);
            fun.drawBLine(dxf, new Vector2[] { t2, t6 }, lineWidth, contour);

            //对于菱形刀片侧切，如果kapr小于90°，在leftview中要显示后面
            if (cutagl * 180 / pi < 90)
            {
                Vector2 rect = fun.Inters(ti1, fun.Polar(ti1, Vector2.Angle(t5, t1), 1), t1, t3);
                fun.drawBLine(dxf, new Vector2[] { t3, rect, ti1 }, lineWidth, contour);

                LwPolyline majorFlank = Pus.AddPointsToLwPolyLine(tii4, tii1, ti1);
                fun.PolyFill(dxf, majorFlank, lineWidth, cutting);
            }

            if (lambdas <= 0.5 * pi / 180)
            {
                LwPolyline leftinsert = Pus.AddPointsToLwPolyLine(tii4, ti4, ti3, tii3);
                leftinsert.IsClosed = true;
                fun.PolyFill(dxf, leftinsert, lineWidth, cutting);
            }
            else
            {
                LwPolyline atcontour = Pus.AddPointsToLwPolyLine(ti1, t9, t4, t5);
                fun.PolyFill(dxf, atcontour, lineWidth, contour);
                LwPolyline tinsert = Pus.AddPointsToLwPolyLine(ti4, ti1, ti2, ti3);
                tinsert.IsClosed = true;
                fun.PolyFill(dxf, tinsert, lineWidth, cutting);
                fun.drawBLine(dxf, new Vector2[] { ti3, tii3, tii4, ti4 }, lineWidth, cutting);
            }
            //标注伪前角
            if (gamao == 0)
                Pus.NeedleDim(dxf, new Line(ti4, fun.Polar(ti4, Vector2.Angle(ti4, ti3) - 1 * pi / 180, 1)), new Line(ti4, fun.Polar(ti4, Vector2.Angle(t1, t3), 1)), offset, "0°", dimensionStyle);
            else
                Pus.NeedleDim(dxf, new Line(ti4, ti3), new Line(ti4, fun.Polar(ti4, Vector2.Angle(t1, t3), 1)), offset, gamao * 180 / pi + "°", dimensionStyle);
            ///
            double isframe = 1;
            try
            {
                isframe = Convert.ToDouble(data["isframe"]);
            }
            catch (Exception) { }

            if (isframe != 0)
            {
                Vector2 p0 = new Vector2((c2.X + t2.X - 420) / 2, (c2.Y + nl2.Y + 297) / 2);
                try
                {
                    Dictionary<string, Vector2> positions = Frame.frameA3X(dxf, p0, new Dictionary<string, object>());
                    fun.writetextofC(dxf, kscale + ":1", positions["比例"], 3.5, 0, 0.6, 3);
                }
                catch (Exception) { }
            }



            dxf.DrawingVariables.AcadVer = DxfVersion.AutoCad2007;
            dxf.Save(path);

        }
        public static void StyleA_InsertT(Dictionary<string, Object> data)
        {
            DxfDocument dxf = new DxfDocument();
            Layer contour = new Layer("contour") { Color = AciColor.Cyan };    //1,轮廓层
            Layer cutting = new Layer("cutting") { Color = AciColor.Red };    //切削层

            string path = Convert.ToString(data["path"]);
            //参数名称取自ISO 5610-2
            double a = 1.6;
            double b = 12;
            double l1 = 70;
            double l2 = 25;
            double f = 12.5;
            double insertAngle = 60 * pi / 180;
            double l3 = 11;
            double h2 = 12;
            double h1 = 12;
            double s = 3.18;
            double alphan = 7 * pi / 180;
            double cutagl = (alphan * 180 / pi - 2) * pi / 180;
            double lambdas = 6;
            double gamao = 0;
            double repsilon = 0;
            #region
            try
            {
                if (data["re"] != null)
                    repsilon = Convert.ToDouble(data["re"]);
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["lams"] != null)
                    lambdas = Convert.ToDouble(data["lams"]) * pi / 180;
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["gamo"] != null)
                    gamao = Convert.ToDouble(data["gamo"]) * pi / 180;
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["lfa"] != null)
                    a = Convert.ToDouble(data["lfa"]);
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["b"] != null)
                    b = Convert.ToDouble(data["b"]);
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["s"] != null)
                    s = Convert.ToDouble(data["s"]);
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["lf"] != null)
                    l1 = Convert.ToDouble(data["lf"]);
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["lh"] != null)
                    l2 = Convert.ToDouble(data["lh"]);
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["wf"] != null)
                    f = Convert.ToDouble(data["wf"]);
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["h"] != null)
                    h2 = Convert.ToDouble(data["h"]);
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["hf"] != null)
                    h1 = Convert.ToDouble(data["hf"]);
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["epsr"] != null)
                    insertAngle = Convert.ToDouble(data["epsr"]) * pi / 180;
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["kapr"] != null)
                    cutagl = Convert.ToDouble(data["kapr"]) * pi / 180;
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["an"] != null)
                    alphan = Convert.ToDouble(data["an"]) * pi / 180;
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["ic"] != null)
                    l3 = Pus.GetLByTIC(Convert.ToDouble(data["ic"]));
            }
            catch (KeyNotFoundException) { }
            #endregion
            //线性变换
            Vector2 zero = new Vector2(0, 0);
            double kscale = 1;
            if (l1 >= 120)
                kscale = 1.5;
            else
                kscale = 2;
            double rotate4T = 0 * pi / 180;
            double ix = fun.Polar(zero, rotate4T, kscale).X;
            double iy = fun.Polar(zero, rotate4T, kscale).Y;
            double jx = fun.Polar(zero, rotate4T + pi / 2, kscale).X;
            double jy = fun.Polar(zero, rotate4T + pi / 2, kscale).Y;
            Matrix3 trans = new Matrix3(
                ix, jx, 0,
                iy, jy, 0,
                0, 0, 1
                );
            double lineWidth = 1;
            ///if一个实体是由线性变换后的实体通过某种方法得到的，该实体也参与了线性变换，不再对其进行线性变换
            Vector2 oc1 = new Vector2(0, 0);
            Vector2 oc2 = new Vector2(oc1.X, oc1.Y + b);
            Vector2 oc10 = new Vector2(oc2.X - l1 + l2, oc1.Y);
            Vector2 oc3 = new Vector2(oc10.X, oc2.Y);
            Vector2 oc4 = new Vector2(oc3.X - 2, oc3.Y);
            Vector2 oc9 = new Vector2(oc10.X - 1, oc10.Y);

            Vector2 c1 = Pus.LinearTrans(trans, oc1);
            Vector2 c2 = Pus.LinearTrans(trans, oc2);
            Vector2 c10 = Pus.LinearTrans(trans, oc10);
            Vector2 c3 = Pus.LinearTrans(trans, oc3);
            Vector2 c4 = Pus.LinearTrans(trans, oc4);
            Vector2 c9 = Pus.LinearTrans(trans, oc9);
            ///刀片部分
            //k点位置参考lc模型k点与i4关系文件"横向进给，>90" 考虑到90°在临界位置，判断使用哪个k点方案(根据ISO 5610-1)
            Vector2 ok = new Vector2(oc1.X - l1, oc2.Y - f);
            Vector2 k = Pus.LinearTrans(trans, ok);
            Vector2 oi3;
            if (cutagl * 180 / pi > 90)
            {
                Vector2 kp = fun.Polar(ok, -pi / 2, repsilon / Math.Tan((pi - cutagl) / 2) - repsilon);
                oi3 = fun.Polar(kp, -pi / 2 - (pi - cutagl), repsilon / Math.Tan(insertAngle / 2) - repsilon / Math.Tan((pi - cutagl) / 2));
            }
            else
            {
                oi3 = fun.Polar(ok, cutagl - pi, repsilon * (1 / Math.Tan(insertAngle / 2) - 1 / Math.Tan((pi - cutagl) / 2)));
            }
            Vector2[] oipoints = Pus.TrianglePoints(oi3, l3, true, cutagl);
            Vector2 oi1 = oipoints[1];
            Vector2 oi2 = oipoints[2];

            Vector2 i1 = Pus.LinearTrans(trans, oi1);
            Vector2 i2 = Pus.LinearTrans(trans, oi2);
            Vector2 i3 = Pus.LinearTrans(trans, oi3);
            LwPolyline insertContour = Pus.AddPointsToLwPolyLine(i3, i1, i2);
            insertContour.IsClosed = true;
            //添加圆弧,这些圆弧的位置是已经参与了线性变换的圆弧，大小没有
            Pus.AglToArc(insertContour, repsilon * kscale);
            ///偏移部分
            double theOffset = s * Math.Tan(alphan);
            Vector2[] oiipoints = Pus.OffsetPoints(theOffset, oipoints);
            Vector2 oii1 = oiipoints[1];
            Vector2 oii2 = oiipoints[2];
            Vector2 oii3 = oiipoints[0];
            Vector2 ii1 = Pus.LinearTrans(trans, oii1);
            Vector2 ii2 = Pus.LinearTrans(trans, oii2);
            Vector2 ii3 = Pus.LinearTrans(trans, oii3);
            ///交点u1，u2
            //u1，u2由线性变换后的实体相交得到，相当于参与了线性变换
            Vector2 u1;
            Vector2 u2;
            if (alphan == 0)
            {
                u1 = insertContour.Vertexes[3].Position;
                u2 = insertContour.Vertexes[0].Position;
            }
            else
            {
                Arc iarc2 = Pus.GetArcFromPline(insertContour, 2);
                List<Vector2> u1s = Pus.LineXArc(iarc2, ii1, ii3);
                if (u1s == null || u1s.Count == 0)
                    u1 = fun.Inters(ii1, ii3, i1, i2);
                else
                    u1 = u1s[0];

                Arc iarc1 = Pus.GetArcFromPline(insertContour, 1);
                List<Vector2> u2s = Pus.LineXArc(iarc1, ii3, ii1);
                if (u2s == null || u2s.Count == 0)
                    u2 = fun.Inters(i2, i3, ii3, ii1);
                else
                    u2 = u2s[0];
            }

            ///交点c11，c12
            Vector2 oc5 = new Vector2(oi2.X, oc4.Y);
            Vector2 oc8 = new Vector2(Pus.KPoint(oi1, oc9, 0.3).X, oc9.Y);

            Vector2 c5 = Pus.LinearTrans(trans, oc5);
            Vector2 n6p = fun.Inters(c2, c5, u2, fun.Polar(u2, Vector2.Angle(i3, i2) + pi / 7, 1));
            Vector2 c6 = Pus.KPoint(u2, n6p, 0.7);
            Vector2 oc6 = Pus.LinearTrans(trans.Inverse(), c6);
            Vector2 c8 = Pus.LinearTrans(trans, oc8);
            ///绘制main视图
            LwPolyline mcontour1 = Pus.AddPointsToLwPolyLine(u1, c8, c9, c10, c1, c2, c3, c4, c5, c6, u2);
            //fun.PolyFill(dxf, mcontour1, lineWidth, contour);
            fun.drawBLine(dxf, Pus.GetV2ArrayFromLwPolyline(mcontour1), lineWidth, contour);
            //LwPolyline mcontour2 = Pus.AddPointsToLwPolyLine(Pus.KPoint(i2,i3,0.5), i2, Pus.KPoint(i2,i1,0.5));
            //fun.PolyFill(dxf, mcontour2, lineWidth, contour);

            fun.PolyFill(dxf, insertContour, lineWidth, cutting);
            fun.drawBLine(dxf, new Vector2[] { c10, c3 }, lineWidth, contour);
            fun.drawBLine(dxf, new Vector2[] { c9, c4 }, lineWidth, contour);
            ///main视图标注
            DimensionStyle dimensionStyle = fun.CreateDimStyle();
            dimensionStyle.TextOffset = 10;
            dimensionStyle.ArrowSize = 0.2;
            dimensionStyle.DimArrow1 = DimensionArrowhead.Closedfilled;
            dimensionStyle.DimArrow2 = DimensionArrowhead.Closedfilled;
            dimensionStyle.TextHeight = kscale;
            dimensionStyle.TextOffset = kscale / 2;
            double offset = 7 * kscale;
            LinearDimension dim_l1 = new LinearDimension(new Line(k, c1), -offset, Vector2.Angle(c10, c1) * 180 / pi, dimensionStyle);
            fun.dxflinedim(dxf, dim_l1, l1);
            LinearDimension dim_l2 = new LinearDimension(new Line(k, c10), -offset * 0.5, Vector2.Angle(c10, c1) * 180 / pi, dimensionStyle);
            fun.dxflinedim(dxf, dim_l2, l2);
            LinearDimension dim_l3 = new LinearDimension(new Line(i1, i2), offset, Pus.Degree(i2, i1), dimensionStyle);
            dim_l3.UserText = l3.ToString().Substring(0, 4);
            dxf.AddEntity(dim_l3);
            LinearDimension dim_f = new LinearDimension(new Line(k, c5), offset, Vector2.Angle(c1, c2) * 180 / pi, dimensionStyle);
            fun.dxflinedim(dxf, dim_f, f);
            LinearDimension dim_b = new LinearDimension(new Line(c1, c2), -offset, Vector2.Angle(c1, c2) * 180 / pi, dimensionStyle);
            fun.dxflinedim(dxf, dim_b, b);
            Angular2LineDimension dim_cutAgl1 = new Angular2LineDimension(new Line(i3, i1), new Line(i3, fun.Polar(i3, Vector2.Angle(i3, i1) - cutagl, 1)), 2 * kscale, dimensionStyle);
            dim_cutAgl1.UserText = cutagl * 180 / pi + "°";
            dxf.AddEntity(dim_cutAgl1);
            //Angular2LineDimension dim_cutAgl2 = new Angular2LineDimension(new Line(i3, i3), new Line(i3, fun.Polar(i3, Vector2.Angle(i3, i3) + cutagl, 1)), 2 * kscale, dimensionStyle);
            //dim_cutAgl2.UserText = cutagl * 180 / pi + "°";
            //dxf.AddEntity(dim_cutAgl2);
            Angular2LineDimension dim_insertagl = new Angular2LineDimension(new Line(i3, i1), new Line(i3, i2), l3 / 2 * kscale, dimensionStyle);
            dim_insertagl.UserText = insertAngle * 180 / pi + "°";
            dxf.AddEntity(dim_insertagl);
            RadialDimension dim_repsilon = new RadialDimension(Pus.GetArcFromPline(insertContour, 1), Pus.Degree(i2, i3), 3 * kscale, dimensionStyle);
            dim_repsilon.UserText = "rε=" + Math.Round(repsilon / kscale, 2);
            dxf.AddEntity(dim_repsilon);

            ///lower视图
            Vector2 ol1 = new Vector2(oc1.X, oc1.Y - offset * 1.8);
            Vector2 ol2 = new Vector2(oc1.X, ol1.Y - h2);
            Vector2 ol3 = new Vector2(oc8.X, ol2.Y);
            Vector2 ol10 = new Vector2(oc10.X, ol1.Y);

            Vector2 nl1 = Pus.LinearTrans(trans, ol1);
            Vector2 nl2 = Pus.LinearTrans(trans, ol2);
            Vector2 nl3 = Pus.LinearTrans(trans, ol3);
            Vector2 nl10 = Pus.LinearTrans(trans, ol10);

            Vector2 oli3 = new Vector2(oi3.X, ol2.Y + h1);
            Vector2[] shankHead = Pus.Diamonds3d(oli3, gamao, lambdas, s, cutagl - pi / 2, 3, false, new Vector2[] {
            oi3,oi1,oi2,oii3,oii1,oii2,oc4,oc5,oc6,oc8,oc9});
            //oli4以新的为准
            oli3 = shankHead[0];
            int i = 1;
            Vector2 oli1 = shankHead[i++];
            Vector2 oli2 = shankHead[i++];
            Vector2 olii3 = shankHead[i++];
            Vector2 olii1 = shankHead[i++];
            Vector2 olii2 = shankHead[i++];

            Vector2 ol4 = shankHead[i++];
            Vector2 ol5 = shankHead[i++];
            Vector2 ol6 = shankHead[i++];
            Vector2 ol8 = shankHead[i++];
            Vector2 ol9 = shankHead[i++];
            Vector2 ol7 = new Vector2(olii3.X, ol3.Y);

            Vector2 nl7 = Pus.LinearTrans(trans, ol7);
            Vector2 li1 = Pus.LinearTrans(trans, oli1);
            Vector2 li2 = Pus.LinearTrans(trans, oli2);
            Vector2 li3 = Pus.LinearTrans(trans, oli3);
            Vector2 lii1 = Pus.LinearTrans(trans, olii1);
            Vector2 lii2 = Pus.LinearTrans(trans, olii2);
            Vector2 lii3 = Pus.LinearTrans(trans, olii3);
            Vector2 nl4 = Pus.LinearTrans(trans, ol4);
            Vector2 nl5 = Pus.LinearTrans(trans, ol5);
            Vector2 nl6 = Pus.LinearTrans(trans, ol6);
            Vector2 nl8 = Pus.LinearTrans(trans, ol8);
            Vector2 nl9 = Pus.LinearTrans(trans, ol9);

            LwPolyline lcontour;
            if (gamao <= 0)
            {
                lcontour = Pus.AddPointsToLwPolyLine(nl1, nl2, nl3, nl7, lii3, lii1, li1, nl8, nl9, nl10);
                lcontour.IsClosed = true;
                fun.PolyFill(dxf, lcontour, lineWidth, contour);

                LwPolyline linsert = Pus.AddPointsToLwPolyLine(lii3, lii1, li1, li3);
                linsert.IsClosed = true;
                fun.PolyFill(dxf, linsert, lineWidth, cutting);
            }
            else
            {
                lcontour = Pus.AddPointsToLwPolyLine(nl1, nl2, nl3, nl7, lii3, lii1, li1, li2, li3, nl6, nl5, nl4, nl9, nl10);
                lcontour.IsClosed = true;
                fun.PolyFill(dxf, lcontour, lineWidth, contour);
                fun.drawBLine(dxf, new Vector2[] { li1, nl8, nl9 }, lineWidth, contour);
                fun.drawBLine(dxf, new Vector2[] { nl8, nl3 }, lineWidth, contour);

                LwPolyline lupperinsert = Pus.AddPointsToLwPolyLine(li1, li2, li3);
                lupperinsert.IsClosed = true;
                fun.PolyFill(dxf, lupperinsert, lineWidth, cutting);
                fun.drawBLine(dxf, new Vector2[] { li3, lii3, lii1, li1 }, lineWidth, cutting);
            }
            //lowwer标注
            LinearDimension dim_h2 = new LinearDimension(new Line(nl1, nl2), offset, Pus.Degree(nl1, nl2), dimensionStyle);
            fun.dxflinedim(dxf, dim_h2, h2);
            LinearDimension dim_h1 = new LinearDimension(new Line(nl7, li3), offset, Pus.Degree(nl7, lii3), dimensionStyle);
            fun.dxflinedim(dxf, dim_h1, h1);
            //标注伪刃倾角
            if (lambdas == 0)
                Pus.NeedleDim(dxf, new Line(li3, fun.Polar(li3, Pus.Degree(li3, li1) + 1, 1)), new Line(li3, fun.Polar(li3, Vector2.Angle(nl3, nl7), 1)), offset, "0°", dimensionStyle);
            else
                Pus.NeedleDim(dxf, new Line(li3, li1), new Line(li3, fun.Polar(li3, Vector2.Angle(nl3, nl7), 1)), offset, lambdas * 180 / pi + "°", dimensionStyle);

            ///
            Vector2 oti3 = new Vector2(oi3.X - offset * 1.2, oi3.Y);
            Vector2[] leftview = Pus.Diamonds3d(oti3, gamao, lambdas, s, cutagl - pi / 2, 3, true,
               new Vector2[] { oi3, oi1, oi2, oii3, oii1, oii2, oc4, oc5, oc6, oc8, oc9 });
            oti3 = leftview[0];
            i = 1;
            Vector2 oti1 = leftview[i++];
            Vector2 oti2 = leftview[i++];
            Vector2 otii3 = leftview[i++];
            Vector2 otii1 = leftview[i++];
            Vector2 otii2 = leftview[i++];
            Vector2 ot4 = leftview[i++];
            Vector2 ot5 = leftview[i++];
            Vector2 ot6 = leftview[i++];
            Vector2 ot8 = leftview[i++];
            Vector2 ot9 = leftview[i++];

            Vector2 ot3 = new Vector2(oti3.X - h1, otii3.Y);
            Vector2 ot1 = new Vector2(ot3.X, ot5.Y);
            Vector2 ot2 = new Vector2(ot3.X, ot6.Y);


            Vector2 t1 = Pus.LinearTrans(trans, ot1);
            Vector2 t2 = Pus.LinearTrans(trans, ot2);
            Vector2 t3 = Pus.LinearTrans(trans, ot3);
            Vector2 t4 = Pus.LinearTrans(trans, ot4);
            Vector2 t5 = Pus.LinearTrans(trans, ot5);
            Vector2 t6 = Pus.LinearTrans(trans, ot6);
            Vector2 t9 = Pus.LinearTrans(trans, ot9);
            Vector2 ti1 = Pus.LinearTrans(trans, oti1);
            Vector2 ti2 = Pus.LinearTrans(trans, oti2);
            Vector2 ti3 = Pus.LinearTrans(trans, oti3);
            Vector2 tii1 = Pus.LinearTrans(trans, otii1);
            Vector2 tii2 = Pus.LinearTrans(trans, otii2);
            Vector2 tii3 = Pus.LinearTrans(trans, otii3);

            LwPolyline tcontour;
            tcontour = Pus.AddPointsToLwPolyLine(t1, t2, t3, tii3, ti3, t6, t5);
            tcontour.IsClosed = true;
            fun.PolyFill(dxf, tcontour, lineWidth, contour);
            fun.drawBLine(dxf, new Vector2[] { t2, t6 }, lineWidth, contour);
            if (lambdas >= 0.5 * pi / 180)
            {
                LwPolyline atcontour = Pus.AddPointsToLwPolyLine(ti1, t9, t4, t5);
                fun.PolyFill(dxf, atcontour, lineWidth, contour);
                LwPolyline tinsert = Pus.AddPointsToLwPolyLine(ti1, ti2, ti3);
                tinsert.IsClosed = true;
                fun.PolyFill(dxf, tinsert, lineWidth, cutting);
            }
            //标注伪前角
            if (gamao == 0)
                Pus.NeedleDim(dxf, new Line(ti3, fun.Polar(ti3, Pus.Degree(ti3, ti2) + 1, 1)), new Line(ti3, fun.Polar(ti3, Vector2.Angle(t1, t3), 1)), offset, "0°", dimensionStyle);
            else
                Pus.NeedleDim(dxf, new Line(ti3, ti2), new Line(ti3, fun.Polar(ti3, Vector2.Angle(t1, t3), 1)), offset, gamao * 180 / pi + "°", dimensionStyle);
            ///
            double isframe = 1;
            try
            {
                isframe = Convert.ToDouble(data["isframe"]);
            }
            catch (Exception) { }


            if (isframe != 0)
            {
                Vector2 p0 = new Vector2((c2.X + t2.X - 420) / 2, (c2.Y + nl2.Y + 297) / 2);
                try
                {
                    Dictionary<string, Vector2> positions = Frame.frameA3X(dxf, p0);
                    fun.writetextofC(dxf, kscale + ":1", positions["比例"], 3.5, 0, 0.6, 3);
                }
                catch (Exception) { }
            }
            dxf.DrawingVariables.AcadVer = DxfVersion.AutoCad2007;
            dxf.Save(path);

        }
        public static void StyleA_InsertR(Dictionary<string, Object> data)
        {
            DxfDocument dxf = new DxfDocument();
            Layer contour = new Layer("contour") { Color = AciColor.Cyan };    //1,轮廓层
            Layer cutting = new Layer("cutting") { Color = AciColor.Red };    //切削层

            string path = Convert.ToString(data["path"]);
            //参数名称取自ISO 5610-4
            double b = 8;
            double l1 = 70;
            double l2 = 15;
            double d = 6;
            double f = 4;
            double h2 = 8;
            double h1 = 8;
            double s = 2.38;
            double alphan = 0 * pi / 180;
            double lambdas = 0;
            double gammao = 0;
            double repsilon = 0;
            #region
            try
            {
                if (data["re"] != null)
                    repsilon = Convert.ToDouble(data["re"]);
                if (repsilon <= 0)
                    repsilon = 0.01;
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["lams"] != null)
                    lambdas = Convert.ToDouble(data["lams"]) * pi / 180;
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["b"] != null)
                    b = Convert.ToDouble(data["b"]);
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["ic"] != null)
                    d = Convert.ToDouble(data["ic"]);
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["s"] != null)
                    s = Convert.ToDouble(data["s"]);
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["lf"] != null)
                    l1 = Convert.ToDouble(data["lf"]);
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["lh"] != null)
                    l2 = Convert.ToDouble(data["lh"]);
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["wf"] != null)
                    f = Convert.ToDouble(data["wf"]);
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["h"] != null)
                    h2 = Convert.ToDouble(data["h"]);
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["hf"] != null)
                    h1 = Convert.ToDouble(data["hf"]);
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["an"] != null)
                    alphan = Convert.ToDouble(data["an"]) * pi / 180;
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["an"] != null)
                    gammao = Convert.ToDouble(data["gamo"]) * pi / 180;
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["an"] != null)
                    lambdas = Convert.ToDouble(data["lams"]) * pi / 180;
            }
            catch (KeyNotFoundException) { }
            #endregion
            double kscale = 1;
            if (l1 >= 120)
                kscale = 1;
            else
                kscale = 1.5;
            double lineWidth = 1;
            //k点位置恒定
            Vector3 k = new Vector3(0, 0, 0);
            RectShank rs = new RectShank(b, l1, f, l2, double.NaN, 4, true, double.NaN, double.NaN, lambdas, true, double.NaN, alphan, s, repsilon);
            Vector3[] shank = rs.Shank;
            //线性变换
            double theta = 0 * pi / 180;
            Matrix3 linearTrans = new Matrix3(
                Math.Cos(theta) * kscale, -Math.Sin(theta) * kscale, 0,
                Math.Sin(theta) * kscale, Math.Cos(theta) * kscale, 0,
                              0, 0, kscale
            );
            for (int i = 0; i < shank.Length; i++)
            {
                shank[i] = linearTrans * shank[i];
            }
            d *= kscale;

            //mview
            LwPolyline msk = Pus.AddPointsToLwPolyLine(shank[4], shank[5], shank[6], shank[7]);
            msk.IsClosed = true;
            Pus.LightFillPline(dxf, msk, lineWidth, contour);

            EntityObject roundInsert = RectShank.RoundInsert(d / 2, gammao);
            List<Vector2> ev2s;//从圆或椭圆实体中获取的点,它们是以原点为中心的;
            List<Vector2> v2s = new List<Vector2>();//偏移后的点的容器
            LwPolyline insertPline;
            int precision = 100;
            if (gammao == 0)
            {
                Circle c = (Circle)roundInsert;
                ev2s = c.PolygonalVertexes(precision);
                for (int i = 0; i < precision; i++)
                {
                    v2s.Add(new Vector2(ev2s[i].X + d / 2, ev2s[i].Y));
                }
                insertPline = Pus.AddPointsToLwPolyLine(v2s);

                LwPolyline p1 = Pus.AddPointsToLwPolyLine(new Vector2(d / 2, d / 2), fun.Polar(new Vector2(d / 2, d / 2), 3 * pi / 180, 1.5 * d), Pus.ToV2(shank[6]));
                p1.Vertexes[1].Bulge = Math.Tan(10 * pi / 180);
                fun.PolyFill(dxf, p1, lineWidth, contour);
                LwPolyline p2 = Pus.AddPointsToLwPolyLine(new Vector2(d / 2, -d / 2), fun.Polar(new Vector2(d / 2, -d / 2), -3 * pi / 180, 1.5 * d), Pus.ToV2(shank[7]));
                p2.Vertexes[1].Bulge = Math.Tan(-10 * pi / 180);
                fun.PolyFill(dxf, p2, lineWidth, contour);
            }
            else
            {
                Ellipse e = (Ellipse)roundInsert;
                ev2s = e.PolygonalVertexes(precision);
                for (int i = 0; i < precision; i++)
                {
                    v2s.Add(new Vector2(ev2s[i].X + d / 2 * Math.Cos(gammao), ev2s[i].Y));
                }
                insertPline = Pus.AddPointsToLwPolyLine(v2s);

                LwPolyline p1 = Pus.AddPointsToLwPolyLine(new Vector2(d / 2, d / 2), fun.Polar(new Vector2(d / 2, d / 2), 3 * pi / 180, 1.5 * d), Pus.ToV2(shank[6]));
                p1.Vertexes[1].Bulge = Math.Tan(10 * pi / 180);
                fun.PolyFill(dxf, p1, lineWidth, contour);
                LwPolyline p2 = Pus.AddPointsToLwPolyLine(new Vector2(d / 2, -d / 2), fun.Polar(new Vector2(d / 2, -d / 2), -3 * pi / 180, 1.5 * d), Pus.ToV2(shank[7]));
                p2.Vertexes[1].Bulge = Math.Tan(-10 * pi / 180);
                fun.PolyFill(dxf, p2, lineWidth, contour);
            }
            insertPline.IsClosed = true;
            Pus.LightFillPline(dxf, insertPline, lineWidth, cutting);

            //mview标注
            DimensionStyle dimensionStyle = new DimensionStyle("mystyle");
            dimensionStyle.ArrowSize = kscale * 1.5;
            dimensionStyle.DimArrow1 = DimensionArrowhead.Closedfilled;
            dimensionStyle.DimArrow2 = DimensionArrowhead.Closedfilled;
            dimensionStyle.TextHeight = kscale * 1.5;
            dimensionStyle.TextOffset = kscale;
            double offset = 7 * kscale;
            LinearDimension dim_b = new LinearDimension(new Line(shank[5], shank[4]), offset, Pus.Degree(shank[5], shank[4]), dimensionStyle);
            fun.dxflinedim(dxf, dim_b, b);
            LinearDimension dim_f = new LinearDimension(new Line(Vector3.Zero, shank[6]), shank[6].X / 2 + offset, Pus.Degree(shank[4], shank[5]), dimensionStyle);
            fun.dxflinedim(dxf, dim_f, f);
            LinearDimension dim_l1 = new LinearDimension(new Line(Vector3.Zero, shank[4]), Math.Abs(shank[4].Y) + offset, 180, dimensionStyle);
            fun.dxflinedim(dxf, dim_l1, l1);
            LinearDimension dim_l2 = new LinearDimension(new Line(shank[6], Vector3.Zero), Math.Abs(shank[6].Y) + offset, 0, dimensionStyle);
            fun.dxflinedim(dxf, dim_l2, l2);

            //zview
            //绕y轴旋转pi/2再平移得到左视图
            Vector3[] zshank = new Vector3[shank.Length];
            Vector3 zviewMkr = new Vector3(0, 1, 0);
            double yR = pi / 2;
            double zoffset = -2 * b * kscale;
            for (int i = 0; i < shank.Length; i++)
            {
                zshank[i] = Pus.Rodrigue(zviewMkr, 1, yR, shank[i]);
                zshank[i].X += zoffset;
            }
            Vector3 zk = k;
            zk.X += zoffset;

            LwPolyline z1 = Pus.AddPointsToLwPolyLine(zshank[6], zshank[7], zshank[3], zshank[2]);
            z1.IsClosed = true;
            fun.PolyFill(dxf, z1, lineWidth, contour);

            Vector2 cen = Pus.ToV2(Pus.KPoint(zshank[6], zshank[7], 0.5));
            Vector2 zd1 = fun.Polar(cen, -pi / 2, d / 2);
            Vector2 zd2 = fun.Polar(zd1, pi, zshank[4].X - zshank[0].X);
            Vector2 zd3 = fun.Polar(zd2, pi / 2, d);
            Vector2 zd4 = fun.Polar(zd3, 0, zshank[4].X - zshank[0].X);
            LwPolyline z2 = Pus.AddPointsToLwPolyLine(zd1, zd2, zd3, zd4);
            z2.IsClosed = true;
            fun.PolyFill(dxf, z2, lineWidth, contour);
            Vector2 zi1 = zd1;
            Vector2 zi2 = fun.Polar(zi1, pi - alphan, s / Math.Cos(alphan));
            Vector2 zi4 = zd4;
            Vector2 zi3 = fun.Polar(zi4, pi + alphan, s / Math.Cos(alphan));
            LwPolyline z3 = Pus.AddPointsToLwPolyLine(zi1, zi2, zi3, zi4);
            z3.IsClosed = true;
            fun.PolyFill(dxf, z3, lineWidth, cutting);

            //lview
            Vector3[] lshank = new Vector3[shank.Length];
            //放倒
            Vector3 laydown = new Vector3(-1, 0, 0);
            double laydownR = pi / 2;
            double loffset = -h2 * 2 * kscale;
            for (int i = 0; i < shank.Length; i++)
            {
                lshank[i] = Pus.Rodrigue(laydown, 1, laydownR, shank[i]);
                lshank[i].Y += loffset;
            }
            Vector3 lk = k;
            lk.Y += loffset;

            LwPolyline lsk = Pus.AddPointsToLwPolyLine(lshank[0], lshank[4], lshank[7], lshank[3]);
            lsk.IsClosed = true;
            fun.PolyFill(dxf, lsk, lineWidth, contour);

            Vector2 lhd1 = new Vector2(d / 2, lshank[7].Y);
            Vector2 lhd2 = new Vector2(s * Math.Tan(alphan), lshank[3].Y);
            Vector2 lhd3 = fun.Polar(lhd2, pi / 2, (h1 - s) * kscale);
            LwPolyline lhd = Pus.AddPointsToLwPolyLine(lhd1, Pus.ToV2(lshank[7]), Pus.ToV2(lshank[3]), lhd2, lhd3);
            fun.PolyFill(dxf, lhd, lineWidth, contour);

            Vector2 li1 = new Vector2(0, lshank[7].Y);
            Vector2 li2 = lhd1;
            Vector2 li3 = fun.Polar(li2, -pi / 2, s * kscale);
            Vector2 li4 = lhd3;
            LwPolyline li = Pus.AddPointsToLwPolyLine(li1, li2, li3, li4);
            li.IsClosed = true;
            fun.PolyFill(dxf, li, lineWidth, cutting);

            //LinearDimension dim_h1 = new LinearDimension(new Line(lhead[0], lk), offset, Pus.Degree(lshank[0], lshank[4]), dimensionStyle);
            //fun.dxflinedim(dxf, dim_h1, h1);
            LinearDimension dim_h2 = new LinearDimension(new Line(lshank[4], lshank[0]), offset, Pus.Degree(lshank[4], lshank[0]), dimensionStyle);
            fun.dxflinedim(dxf, dim_h2, h2);

            //图框
            Vector2 a3xsize = Frame.A3X;
            double isframe = 0;
            try
            {
                isframe = Convert.ToDouble(data["isframe"]);
            }
            catch (KeyNotFoundException) { }
            if (isframe != 0)
            {
                Vector2 EntitysCenter = new Vector2((shank[4].X + zshank[0].X) / 2, (shank[4].Y + lshank[0].Y) / 2);
                Vector2 p0 = new Vector2(EntitysCenter.X - a3xsize.X / 2, EntitysCenter.Y + a3xsize.Y / 2);
                Dictionary<string, Vector2> positions = Frame.frameA3X(dxf, p0);
                Vector2 kp = p0;
                try
                {
                    kp = positions["比例"];
                    fun.writetextofC(dxf, kscale + ":1", positions["比例"], 3.5, 0, 0.6, 3);
                }
                catch (Exception) { }
            }

            dxf.DrawingVariables.AcadVer = DxfVersion.AutoCad2007;
            dxf.Save(path);
        }
        //B型刀头 横小
        public static void StyleB_InsertC(Dictionary<string, Object> data)
        {

            DxfDocument dxf = new DxfDocument();
            Layer contour = new Layer("contour") { Color = AciColor.Cyan };    //1,轮廓层
            Layer cutting = new Layer("cutting") { Color = AciColor.Red };    //切削层

            string path = Convert.ToString(data["path"]);
            //参数名称取自ISO 5610
            double b = 8;
            double l1 = 70;
            double l2 = 12;
            double f = 7;
            double insertAngle = 100 * pi / 180;
            double l3 = 6.4;
            double h2 = 8;
            double h1 = 8;
            double s = 2.38;
            double alphan = 7 * pi / 180;
            double cutagl = 75 * pi / 180;
            double lambdas = 0;
            double gamao = 0;
            double repsilon = 0;
            #region
            try
            {
                if (data["re"] != null)
                    repsilon = Convert.ToDouble(data["re"]);
                if (repsilon <= 0)
                    repsilon = 0.01;
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["lams"] != null)
                    lambdas = Math.Abs(Convert.ToDouble(data["lams"]) * pi / 180);
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["gamo"] != null)
                    gamao = Math.Abs(Convert.ToDouble(data["gamo"]) * pi / 180);
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["b"] != null)
                    b = Convert.ToDouble(data["b"]);
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["s"] != null)
                    s = Convert.ToDouble(data["s"]);
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["lf"] != null)
                    l1 = Convert.ToDouble(data["lf"]);
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["lh"] != null)
                    l2 = Convert.ToDouble(data["lh"]);
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["wf"] != null)
                    f = Convert.ToDouble(data["wf"]);
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["h"] != null)
                    h2 = Convert.ToDouble(data["h"]);
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["hf"] != null)
                    h1 = Convert.ToDouble(data["hf"]);
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["epsr"] != null)
                    insertAngle = pi - Convert.ToDouble(data["epsr"]) * pi / 180;
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["kapr"] != null)
                    cutagl = Convert.ToDouble(data["kapr"]) * pi / 180;
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["an"] != null)
                    alphan = Convert.ToDouble(data["an"]) * pi / 180;
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["ic"] != null)
                    l3 = Pus.GetLByIC(Convert.ToDouble(data["ic"]), insertAngle);
            }
            catch (KeyNotFoundException) { }
            #endregion
            double kscale = 1;
            if (l1 >= 120)
                kscale = 1;
            else
                kscale = 1.5;
            double lineWidth = 1;
            //k点位置恒定
            Vector3 k = new Vector3(0, 0, 0);
            Vector3 b2 = new Vector3(k.X + l1, k.Y + f, k.Z - h1);
            Vector3 b1 = new Vector3(b2.X, b2.Y - b, b2.Z);
            Vector3 b6 = new Vector3(k.X + l2, b1.Y, b1.Z);

            //刀杆顶面
            Vector3 u1 = new Vector3(b1.X, b1.Y, b1.Z + h2);
            Vector3 u2 = new Vector3(b2.X, b2.Y, b2.Z + h2);
            Vector3 u3 = new Vector3(b6.X, b2.Y, b2.Z + h2);
            double guai = kscale;
            Vector3 u3p = new Vector3(u3.X - guai, u3.Y, u3.Z);
            Vector3 u4 = new Vector3(b6.X, b6.Y, b6.Z + h2);
            Vector3 u4p = new Vector3(u4.X - guai, u4.Y, u4.Z);

            //i4 = fun.polar(K,kapr-pi,r(1/tan(epsr/2)-1/tan((pi-karp)/2)))
            Vector2 twoi4 = fun.Polar(Vector2.Zero, cutagl - pi, repsilon / Math.Tan(insertAngle / 2) - repsilon / Math.Tan((pi - cutagl) / 2));
            Vector2[] twois = Pus.DiamondPoints(twoi4, l3, insertAngle, true, cutagl);
            Vector2 twoi1 = twois[1];
            Vector2 twoi2 = twois[2];
            Vector2 twoi3 = twois[3];
            double theoffset = Math.Tan(alphan) * s;
            Vector2[] twoiis = Pus.OffsetPoints(theoffset, twois);
            Vector2 twoii4 = twoiis[0];
            Vector2 twoii3 = twoiis[3];
            Vector2 twoii1 = twoiis[1];
            Vector2 twoii2 = twoiis[2];

            //刀头面
            Vector3 i4 = new Vector3(twoi4.X, twoi4.Y, k.Z);
            Vector3 i3 = new Vector3(twoi3.X, twoi3.Y, k.Z);
            Vector3 i2 = new Vector3(twoi2.X, twoi2.Y, k.Z);
            Vector3 i1 = new Vector3(twoi1.X, twoi1.Y, k.Z);
            Vector3 dt0 = Pus.ToV3(Pus.IntersOnP(i2, i1, u1, u4), k.Z);
            Vector3 dt1 = u4p;
            Vector3 dt2 = u3p;
            Vector2 xx = Pus.IntersOnP(i3, i4, u2, u3);
            Vector3 dt4 = Pus.KPoint(i3, new Vector3(xx.X, xx.Y, u3.Z), 0.7);
            Vector3 dt3 = Pus.KPoint(u3, new Vector3(xx.X, xx.Y, u3.Z), 0.85);

            Vector3 bdt1 = new Vector3(dt1.X, dt1.Y, b1.Z);
            Vector3 b5 = new Vector3(twoii4.X, twoii4.Y, b1.Z);
            Vector3 b4 = new Vector3(dt4.X, dt4.Y, b1.Z);
            Vector3 b3 = new Vector3(dt3.X, dt3.Y, b1.Z);

            Vector3 ii4 = new Vector3(twoii4.X, twoii4.Y, k.Z - s);
            Vector3 ii3 = new Vector3(twoii3.X, twoii3.Y, k.Z - s);
            Vector3 ii1 = new Vector3(twoii1.X, twoii1.Y, k.Z - s);
            Vector3 ii2 = new Vector3(twoii2.X, twoii2.Y, k.Z - s);

            i4 = Pus.LinearTrans(kscale, i4);
            i3 = Pus.LinearTrans(kscale, i3);
            i2 = Pus.LinearTrans(kscale, i2);
            i1 = Pus.LinearTrans(kscale, i1);
            dt0 = Pus.LinearTrans(kscale, dt0);
            dt1 = Pus.LinearTrans(kscale, dt1);
            dt2 = Pus.LinearTrans(kscale, dt2);
            dt3 = Pus.LinearTrans(kscale, dt3);
            dt4 = Pus.LinearTrans(kscale, dt4);

            ii4 = Pus.LinearTrans(kscale, ii4);
            ii3 = Pus.LinearTrans(kscale, ii3);
            ii2 = Pus.LinearTrans(kscale, ii2);
            ii1 = Pus.LinearTrans(kscale, ii1);

            b1 = Pus.LinearTrans(kscale, b1);
            b2 = Pus.LinearTrans(kscale, b2);
            b3 = Pus.LinearTrans(kscale, b3);
            b4 = Pus.LinearTrans(kscale, b4);
            b5 = Pus.LinearTrans(kscale, b5);
            b6 = Pus.LinearTrans(kscale, b6);
            bdt1 = Pus.LinearTrans(kscale, bdt1);

            u1 = Pus.LinearTrans(kscale, u1);
            u2 = Pus.LinearTrans(kscale, u2);
            u3 = Pus.LinearTrans(kscale, u3);
            u3p = Pus.LinearTrans(kscale, u3p);
            u4 = Pus.LinearTrans(kscale, u4);
            u4p = Pus.LinearTrans(kscale, u4p);


            //主视图
            LwPolyline mshank = Pus.AddPointsToLwPolyLine(u1, u2, u3, u4);
            mshank.IsClosed = true;
            fun.PolyFill(dxf, mshank, lineWidth, contour);

            LwPolyline minsert = Pus.AddPointsToLwPolyLine(i4, i1, i2, i3);
            minsert.IsClosed = true;
            Pus.AglToArc(minsert, repsilon);

            LwPolyline mhead = Pus.AddPointsToLwPolyLine(i3, i2, i1, dt1, dt2, dt3, dt4, i3);
            mhead.IsClosed = true;
            fun.PolyFill(dxf, mhead, lineWidth, contour);
            LwPolyline mheadc1 = Pus.AddPointsToLwPolyLine(dt1, u4);
            fun.PolyFill(dxf, mheadc1, lineWidth, contour);
            LwPolyline mheadc2 = Pus.AddPointsToLwPolyLine(dt2, u3);
            fun.PolyFill(dxf, mheadc2, lineWidth, contour);

            fun.PolyFill(dxf, minsert, lineWidth, cutting);
            //m视图标注
            DimensionStyle dimensionStyle = new DimensionStyle("mystyle");
            dimensionStyle.ArrowSize = kscale * 1.2;
            dimensionStyle.DimArrow1 = DimensionArrowhead.Closedfilled;
            dimensionStyle.DimArrow2 = DimensionArrowhead.Closedfilled;
            dimensionStyle.TextHeight = kscale;
            dimensionStyle.TextOffset = kscale / 2;
            double offset = 7 * kscale;
            LinearDimension dim_f = new LinearDimension(new Line(new Vector2(k.X, k.Y), new Vector2(b3.X, b3.Y)), offset * 1.5, Pus.Degree(b1, b2), dimensionStyle);
            fun.dxflinedim(dxf, dim_f, f);
            LinearDimension dim_l1 = new LinearDimension(new Line(new Vector2(k.X, k.Y), new Vector2(b1.X, b1.Y)), offset * 1.5, Pus.Degree(new Vector2(b1.X, b1.Y), new Vector2(b6.X, b6.Y)), dimensionStyle);
            fun.dxflinedim(dxf, dim_l1, l1);
            LinearDimension dim_l2 = new LinearDimension(new Line(new Vector2(k.X, k.Y), new Vector2(u4.X, u4.Y)), offset, Pus.Degree(new Vector2(u1.X, u1.Y), new Vector2(u4.X, u4.Y)), dimensionStyle);
            fun.dxflinedim(dxf, dim_l2, l2);
            //LinearDimension dim_l3 = new LinearDimension(new Line(i2, i3), offset, Pus.Degree(new Vector2(i3.X, i3.Y), new Vector2(i2.X, i2.Y)), dimensionStyle);
            //fun.dxflinedim(dxf, dim_l3, Math.Round(l3, 2));
            LinearDimension dim_b = new LinearDimension(new Line(new Vector2(u1.X, u1.Y), new Vector2(u2.X, u2.Y)), offset, Pus.Degree(new Vector2(u2.X, u2.Y), new Vector2(u1.X, u1.Y)), dimensionStyle);
            fun.dxflinedim(dxf, dim_b, b);
            //Angular2LineDimension dim_insertAgl = new Angular2LineDimension(new Line(i4, i3), new Line(i4, i1), offset * 0.5, dimensionStyle);
            //dim_insertAgl.UserText = Math.Round(insertAngle * 180 / pi, 2) + "°";
            //dxf.AddEntity(dim_insertAgl);
            Angular2LineDimension dim_cutagl = new Angular2LineDimension(new Line(i4, i1), new Line(new Vector2(i4.X, i4.Y), fun.Polar(new Vector2(i4.X, i4.Y), -pi / 2, 1)), offset * 0.4, dimensionStyle);
            dim_cutagl.UserText = Math.Round(cutagl * 180 / pi, 2) + "°";
            dxf.AddEntity(dim_cutagl);
            //RadialDimension dim_repsilon = new RadialDimension(Pus.GetArcFromPline(minsert, 1), Pus.Degree(i3, i4) - 10, offset * 0.5, dimensionStyle);
            //dim_repsilon.UserText = "rε=" + repsilon;
            //dxf.AddEntity(dim_repsilon);
            //放倒(所有点)尚未平移到下方，因为只能绕着原点k所在轴旋转
            Vector3 rotate = new Vector3(-1, 0, 0);
            double rotateAgl = pi / 2;
            i4 = Pus.Rodrigue(rotate, 1, rotateAgl, i4);
            i3 = Pus.Rodrigue(rotate, 1, rotateAgl, i3);
            i2 = Pus.Rodrigue(rotate, 1, rotateAgl, i2);
            i1 = Pus.Rodrigue(rotate, 1, rotateAgl, i1);

            dt0 = Pus.Rodrigue(rotate, 1, rotateAgl, dt0);
            dt1 = Pus.Rodrigue(rotate, 1, rotateAgl, dt1);
            dt2 = Pus.Rodrigue(rotate, 1, rotateAgl, dt2);
            dt3 = Pus.Rodrigue(rotate, 1, rotateAgl, dt3);
            dt4 = Pus.Rodrigue(rotate, 1, rotateAgl, dt4);

            ii4 = Pus.Rodrigue(rotate, 1, rotateAgl, ii4);
            ii3 = Pus.Rodrigue(rotate, 1, rotateAgl, ii3);
            ii2 = Pus.Rodrigue(rotate, 1, rotateAgl, ii2);
            ii1 = Pus.Rodrigue(rotate, 1, rotateAgl, ii1);

            b1 = Pus.Rodrigue(rotate, 1, rotateAgl, b1);
            b2 = Pus.Rodrigue(rotate, 1, rotateAgl, b2);
            b3 = Pus.Rodrigue(rotate, 1, rotateAgl, b3);
            b4 = Pus.Rodrigue(rotate, 1, rotateAgl, b4);
            b5 = Pus.Rodrigue(rotate, 1, rotateAgl, b5);
            b6 = Pus.Rodrigue(rotate, 1, rotateAgl, b6);
            bdt1 = Pus.Rodrigue(rotate, 1, rotateAgl, bdt1);

            u1 = Pus.Rodrigue(rotate, 1, rotateAgl, u1);
            u2 = Pus.Rodrigue(rotate, 1, rotateAgl, u2);
            u3 = Pus.Rodrigue(rotate, 1, rotateAgl, u3);
            u3p = Pus.Rodrigue(rotate, 1, rotateAgl, u3p);
            u4 = Pus.Rodrigue(rotate, 1, rotateAgl, u4);
            u4p = Pus.Rodrigue(rotate, 1, rotateAgl, u4p);

            //创建lambds
            rotate = new Vector3(Math.Sin(cutagl - pi / 2), k.Z, Math.Cos(cutagl - pi / 2));
            rotateAgl = lambdas;
            i4 = Pus.Rodrigue(rotate, 1, rotateAgl, i4);
            i3 = Pus.Rodrigue(rotate, 1, rotateAgl, i3);
            i2 = Pus.Rodrigue(rotate, 1, rotateAgl, i2);
            i1 = Pus.Rodrigue(rotate, 1, rotateAgl, i1);

            ii4 = Pus.Rodrigue(rotate, 1, rotateAgl, ii4);
            ii3 = Pus.Rodrigue(rotate, 1, rotateAgl, ii3);
            ii2 = Pus.Rodrigue(rotate, 1, rotateAgl, ii2);
            ii1 = Pus.Rodrigue(rotate, 1, rotateAgl, ii1);

            dt0 = Pus.Rodrigue(rotate, 1, rotateAgl, dt0);
            dt1 = Pus.Rodrigue(rotate, 1, rotateAgl, dt1);
            dt2 = Pus.Rodrigue(rotate, 1, rotateAgl, dt2);
            dt3 = Pus.Rodrigue(rotate, 1, rotateAgl, dt3);
            dt4 = Pus.Rodrigue(rotate, 1, rotateAgl, dt4);

            //创建gamo
            double disi1_i4 = Vector3.Distance(i1, i4);
            rotate = (i1 - i4) / disi1_i4;
            rotateAgl = gamao;
            i4 = Pus.Rodrigue(rotate, 1, rotateAgl, i4);
            i3 = Pus.Rodrigue(rotate, 1, rotateAgl, i3);
            i2 = Pus.Rodrigue(rotate, 1, rotateAgl, i2);
            i1 = Pus.Rodrigue(rotate, 1, rotateAgl, i1);

            ii4 = Pus.Rodrigue(rotate, 1, rotateAgl, ii4);
            ii3 = Pus.Rodrigue(rotate, 1, rotateAgl, ii3);
            ii2 = Pus.Rodrigue(rotate, 1, rotateAgl, ii2);
            ii1 = Pus.Rodrigue(rotate, 1, rotateAgl, ii1);

            dt0 = Pus.Rodrigue(rotate, 1, rotateAgl, dt0);
            dt1 = Pus.Rodrigue(rotate, 1, rotateAgl, dt1);
            dt2 = Pus.Rodrigue(rotate, 1, rotateAgl, dt2);
            dt3 = Pus.Rodrigue(rotate, 1, rotateAgl, dt3);
            dt4 = Pus.Rodrigue(rotate, 1, rotateAgl, dt4);

            //重新计算刀头的点
            Face3d faceLS = new Face3d(b1, u1, u4);
            Vector3 dtt0 = Pus.Inters(faceLS, new Line(ii4, ii1));

            Face3d face4dt = new Face3d(dt2, dt3, dt4);
            Vector3 v4dt = u2 - b2;
            dt1 = Pus.Inters(face4dt, new Line(u4p, u4p + v4dt));
            dt2 = Pus.Inters(face4dt, new Line(u3p, u3p + v4dt));
            dt3 = Pus.Inters(face4dt, new Line(b3, b3 + v4dt));
            dt4 = Pus.Inters(face4dt, new Line(b4, b4 + v4dt));

            Face3d faceChamfer = new Face3d(dt3, dt4, b4);
            Vector3 dtt4 = Pus.Inters(faceChamfer, new Line(ii4, ii3));

            Face3d face4buttom = new Face3d(b1, b2, b3);
            b5 = Pus.Inters(face4buttom, new Line(ii4, ii4 + v4dt));
            Vector3 bx = Pus.Inters(face4buttom, new Line(ii1, ii1 + v4dt));
            bdt1 = Pus.Inters(face4buttom, new Line(dt1, dt1 + v4dt));
            Vector3 bdt0 = Pus.Inters(face4buttom, new Line(dtt0, dtt0 + v4dt));

            //平移所有点到下方
            Vector3 voff = new Vector3(0, -b * kscale - offset * 1.5, 0);
            Vector3 mk = Pus.OffsetXY(voff, k);
            Vector3 mi4 = Pus.OffsetXY(voff, i4);
            Vector3 mi3 = Pus.OffsetXY(voff, i3);
            Vector3 mi2 = Pus.OffsetXY(voff, i2);
            Vector3 mi1 = Pus.OffsetXY(voff, i1);

            Vector3 mdt0 = Pus.OffsetXY(voff, dt0);
            Vector3 mdtt0 = Pus.OffsetXY(voff, dtt0);
            Vector3 mdt1 = Pus.OffsetXY(voff, dt1);
            Vector3 mdt2 = Pus.OffsetXY(voff, dt2);
            Vector3 mdt3 = Pus.OffsetXY(voff, dt3);
            Vector3 mdt4 = Pus.OffsetXY(voff, dt4);
            Vector3 mii4 = Pus.OffsetXY(voff, ii4);
            Vector3 mii3 = Pus.OffsetXY(voff, ii3);
            Vector3 mii2 = Pus.OffsetXY(voff, ii2);
            Vector3 mii1 = Pus.OffsetXY(voff, ii1);

            Vector3 mb1 = Pus.OffsetXY(voff, b1);
            Vector3 mb2 = Pus.OffsetXY(voff, b2);
            Vector3 mb3 = Pus.OffsetXY(voff, b3);
            Vector3 mb4 = Pus.OffsetXY(voff, b4);
            Vector3 mb5 = Pus.OffsetXY(voff, b5);
            Vector3 mb6 = Pus.OffsetXY(voff, b6);
            Vector3 mbx = Pus.OffsetXY(voff, bx);
            Vector3 mbdt1 = Pus.OffsetXY(voff, bdt1);
            Vector3 mbdt0 = Pus.OffsetXY(voff, bdt0);

            Vector3 mu1 = Pus.OffsetXY(voff, u1);
            Vector3 mu2 = Pus.OffsetXY(voff, u2);
            Vector3 mu3 = Pus.OffsetXY(voff, u3);
            Vector3 mu4 = Pus.OffsetXY(voff, u4);

            //faceLS
            LwPolyline lshank = Pus.AddPointsToLwPolyLine(mdt0, mdt1, mu4, mu1, mb1, mbdt0, mdtt0);
            lshank.IsClosed = true;
            fun.PolyFill(dxf, lshank, lineWidth, contour);
            //LwPolyline lshank_dt = Pus.AddPointsToLwPolyLine(mdt1, mu4);
            //fun.PolyFill(dxf, lshank_dt, lineWidth, contour);
            LwPolyline lshank_dt1 = Pus.AddPointsToLwPolyLine(mdt2, mu3);
            fun.PolyFill(dxf, lshank_dt1, lineWidth, contour);

            LwPolyline lhead = Pus.AddPointsToLwPolyLine(mii4, mb5, mbdt0, mdtt0, mdt0, mdt1);
            fun.PolyFill(dxf, lhead, lineWidth, contour);
            //LwPolyline lhead1 = Pus.AddPointsToLwPolyLine(mbdt1, mb6);
            //fun.PolyFill(dxf, lhead1, lineWidth, contour);
            //LwPolyline lhead2 = Pus.AddPointsToLwPolyLine(mdt1, mi1);
            //fun.PolyFill(dxf, lhead2, lineWidth, contour);
            //LwPolyline lhead3 = Pus.AddPointsToLwPolyLine(mdt1, mbdt1);
            //fun.PolyFill(dxf, lhead3, lineWidth, contour);
            LwPolyline lhead4 = Pus.AddPointsToLwPolyLine(mdtt0, mii1);
            fun.PolyFill(dxf, lhead4, lineWidth, contour);
            LwPolyline lhead5 = Pus.AddPointsToLwPolyLine(mbdt0, mb6);
            fun.PolyFill(dxf, lhead5, lineWidth, contour);
            if (gamao > 0)
            {
                LwPolyline lheadu = Pus.AddPointsToLwPolyLine(mdt1, mdt2, mdt3, mdt4, mi3);
                fun.PolyFill(dxf, lheadu, lineWidth, contour);

                LwPolyline linsertu = Pus.AddPointsToLwPolyLine(mi4, mi1, mi2, mi3);
                linsertu.IsClosed = true;
                fun.PolyFill(dxf, linsertu, lineWidth, cutting);
            }

            LwPolyline linsertf = Pus.AddPointsToLwPolyLine(mi4, mii4, mii1, mi1);
            linsertf.IsClosed = true;
            fun.PolyFill(dxf, linsertf, lineWidth, cutting);
            //l视图标注
            LinearDimension dim_h1 = new LinearDimension(new Line(new Vector2(mk.X, mk.Y), new Vector2(mb5.X, mb5.Y)), offset * 0.5, Pus.Degree(b1, u1), dimensionStyle);
            fun.dxflinedim(dxf, dim_h1, h1);
            LinearDimension dim_h2 = new LinearDimension(new Line(new Vector2(mu1.X, mu1.Y), new Vector2(mb1.X, mb1.Y)), offset, Pus.Degree(u1, b1), dimensionStyle);
            fun.dxflinedim(dxf, dim_h2, h2);
            if (lambdas == 0)
                Pus.NeedleDim(dxf, new Line(new Vector2(mi4.X, mi4.Y), fun.Polar(new Vector2(mi4.X, mi4.Y), pi / 180, 1)), new Line(mi4, mi4 + mu4 - mu2), kscale * offset, "λs=0°", dimensionStyle);
            else
                Pus.NeedleDim(dxf, new Line(mi4, mi1), new Line(mi4, mi4 + mu4 - mu2), kscale * offset, "λs=" + Math.Round(lambdas * 180 / pi, 2) + "°", dimensionStyle);
            //左视图
            //所有点移动到原点
            //立正
            rotate = new Vector3(1, 0, 0);
            rotateAgl = pi / 2;
            Vector3 zi4 = Pus.Rodrigue(rotate, 1, rotateAgl, i4);
            Vector3 zi3 = Pus.Rodrigue(rotate, 1, rotateAgl, i3);
            Vector3 zi2 = Pus.Rodrigue(rotate, 1, rotateAgl, i2);
            Vector3 zi1 = Pus.Rodrigue(rotate, 1, rotateAgl, i1);
            Vector3 zdt1 = Pus.Rodrigue(rotate, 1, rotateAgl, dt1);
            Vector3 zdt2 = Pus.Rodrigue(rotate, 1, rotateAgl, dt2);
            Vector3 zdt3 = Pus.Rodrigue(rotate, 1, rotateAgl, dt3);
            Vector3 zdt4 = Pus.Rodrigue(rotate, 1, rotateAgl, dt4);

            Vector3 zii4 = Pus.Rodrigue(rotate, 1, rotateAgl, ii4);
            Vector3 zii3 = Pus.Rodrigue(rotate, 1, rotateAgl, ii3);
            Vector3 zii2 = Pus.Rodrigue(rotate, 1, rotateAgl, ii2);
            Vector3 zii1 = Pus.Rodrigue(rotate, 1, rotateAgl, ii1);

            Vector3 zb1 = Pus.Rodrigue(rotate, 1, rotateAgl, b1);
            Vector3 zb2 = Pus.Rodrigue(rotate, 1, rotateAgl, b2);
            Vector3 zb3 = Pus.Rodrigue(rotate, 1, rotateAgl, b3);
            Vector3 zb4 = Pus.Rodrigue(rotate, 1, rotateAgl, b4);
            Vector3 zb5 = Pus.Rodrigue(rotate, 1, rotateAgl, b5);
            Vector3 zb6 = Pus.Rodrigue(rotate, 1, rotateAgl, b6);
            Vector3 zbx = Pus.Rodrigue(rotate, 1, rotateAgl, bx);
            Vector3 zbdt1 = Pus.Rodrigue(rotate, 1, rotateAgl, bdt1);

            Vector3 zu1 = Pus.Rodrigue(rotate, 1, rotateAgl, u1);
            Vector3 zu2 = Pus.Rodrigue(rotate, 1, rotateAgl, u2);
            Vector3 zu3 = Pus.Rodrigue(rotate, 1, rotateAgl, u3);
            Vector3 zu4 = Pus.Rodrigue(rotate, 1, rotateAgl, u4);

            //绕y转，露出左面
            rotate = new Vector3(0, 1, 0);
            rotateAgl = pi / 2;
            zi4 = Pus.Rodrigue(rotate, 1, rotateAgl, zi4);
            zi3 = Pus.Rodrigue(rotate, 1, rotateAgl, zi3);
            zi2 = Pus.Rodrigue(rotate, 1, rotateAgl, zi2);
            zi1 = Pus.Rodrigue(rotate, 1, rotateAgl, zi1);
            zdt1 = Pus.Rodrigue(rotate, 1, rotateAgl, zdt1);
            zdt2 = Pus.Rodrigue(rotate, 1, rotateAgl, zdt2);
            zdt3 = Pus.Rodrigue(rotate, 1, rotateAgl, zdt3);
            zdt4 = Pus.Rodrigue(rotate, 1, rotateAgl, zdt4);

            zii4 = Pus.Rodrigue(rotate, 1, rotateAgl, zii4);
            zii3 = Pus.Rodrigue(rotate, 1, rotateAgl, zii3);
            zii2 = Pus.Rodrigue(rotate, 1, rotateAgl, zii2);
            zii1 = Pus.Rodrigue(rotate, 1, rotateAgl, zii1);

            zb1 = Pus.Rodrigue(rotate, 1, rotateAgl, zb1);
            zb2 = Pus.Rodrigue(rotate, 1, rotateAgl, zb2);
            zb3 = Pus.Rodrigue(rotate, 1, rotateAgl, zb3);
            zb4 = Pus.Rodrigue(rotate, 1, rotateAgl, zb4);
            zb5 = Pus.Rodrigue(rotate, 1, rotateAgl, zb5);
            zb6 = Pus.Rodrigue(rotate, 1, rotateAgl, zb6);
            zbx = Pus.Rodrigue(rotate, 1, rotateAgl, zbx);
            zbdt1 = Pus.Rodrigue(rotate, 1, rotateAgl, zbdt1);

            zu1 = Pus.Rodrigue(rotate, 1, rotateAgl, zu1);
            zu2 = Pus.Rodrigue(rotate, 1, rotateAgl, zu2);
            zu3 = Pus.Rodrigue(rotate, 1, rotateAgl, zu3);
            zu4 = Pus.Rodrigue(rotate, 1, rotateAgl, zu4);

            //平移
            voff = new Vector3(-b * kscale - offset * 2, 0, 0);
            zi4 = Pus.OffsetXY(voff, zi4);
            zi3 = Pus.OffsetXY(voff, zi3);
            zi2 = Pus.OffsetXY(voff, zi2);
            zi1 = Pus.OffsetXY(voff, zi1);
            zdt1 = Pus.OffsetXY(voff, zdt1);
            zdt2 = Pus.OffsetXY(voff, zdt2);
            zdt3 = Pus.OffsetXY(voff, zdt3);
            zdt4 = Pus.OffsetXY(voff, zdt4);

            zii4 = Pus.OffsetXY(voff, zii4);
            zii3 = Pus.OffsetXY(voff, zii3);
            zii2 = Pus.OffsetXY(voff, zii2);
            zii1 = Pus.OffsetXY(voff, zii1);

            zb1 = Pus.OffsetXY(voff, zb1);
            zb2 = Pus.OffsetXY(voff, zb2);
            zb3 = Pus.OffsetXY(voff, zb3);
            zb4 = Pus.OffsetXY(voff, zb4);
            zb5 = Pus.OffsetXY(voff, zb5);
            zb6 = Pus.OffsetXY(voff, zb6);
            zbx = Pus.OffsetXY(voff, zbx);
            zbdt1 = Pus.OffsetXY(voff, zbdt1);

            zu1 = Pus.OffsetXY(voff, zu1);
            zu2 = Pus.OffsetXY(voff, zu2);
            zu3 = Pus.OffsetXY(voff, zu3);
            zu4 = Pus.OffsetXY(voff, zu4);

            //左视图绘制
            LwPolyline zshank = Pus.AddPointsToLwPolyLine(zii4, zb5, zb4, zb3, zdt3, zdt4, zi3);
            fun.PolyFill(dxf, zshank, lineWidth, contour);
            LwPolyline zshankb = Pus.AddPointsToLwPolyLine(zdt1, zb1, zb2);
            fun.PolyFill(dxf, zshankb, lineWidth, contour);
            LwPolyline zshank2 = Pus.AddPointsToLwPolyLine(zb4, zdt4);
            fun.PolyFill(dxf, zshank2, lineWidth, contour);
            if (lambdas > 0)
            {
                LwPolyline zshank1 = Pus.AddPointsToLwPolyLine(zdt3, zdt2, zdt1, zi1);
                fun.PolyFill(dxf, zshank1, lineWidth, contour);

                LwPolyline zinsert = Pus.AddPointsToLwPolyLine(zi4, zi1, zi2, zi3);
                zinsert.IsClosed = true;
                fun.PolyFill(dxf, zinsert, lineWidth, cutting);
            }

            LwPolyline zlen1 = Pus.AddPointsToLwPolyLine(zi3, zii3, zii4, zi4);
            zlen1.IsClosed = true;
            fun.PolyFill(dxf, zlen1, lineWidth, cutting);

            if (cutagl < pi / 2)
            {
                LwPolyline zlen2 = Pus.AddPointsToLwPolyLine(zii4, zii1, zi1, zi4);
                fun.PolyFill(dxf, zlen2, lineWidth, cutting);
            }
            //if (zdt1.Y > zu4.Y)
            //{
            //    Vector2 visible = Pus.IntersOnP(zi4, zi1, zb4, zu4);
            //    LwPolyline visiLine = Pus.AddPointsToLwPolyLine(zdt1, zu4);
            //    Pus.AddPointsToLwPolyLine(visiLine, visible);
            //    fun.PolyFill(dxf, visiLine, lineWidth, contour);
            //}
            //左视图标注
            //刃倾角
            if (gamao == 0)
                Pus.NeedleDim(dxf, new Line(new Vector2(zi4.X, zi4.Y), fun.Polar(new Vector2(zi4.X, zi4.Y), Pus.AngleOnP(zi3, zi4) + pi / 180, 1)), new Line(zi3, zi4), offset * 1.5, "γo=0°", dimensionStyle);
            else
                Pus.NeedleDim(dxf, new Line(zi3, zi4), new Line(new Vector2(zi4.X, zi4.Y), fun.Polar(new Vector2(zi4.X, zi4.Y), Pus.AngleOnP(zi3, zi4) + gamao, 1)), offset * 1.5, "γo=" + Math.Round(lambdas * 180 / pi, 2) + "°", dimensionStyle);

            //LinearDimension dim_s = new LinearDimension(new Line(zi4, zii4), offset, Pus.Degree(zi4, zi3) + 90, dimensionStyle);
            //fun.dxflinedim(dxf, dim_s, s);

            //后角
            if (alphan == 0)
                Pus.NeedleDim(dxf, new Line(zi4, zii4), new Line(new Vector2(zi4.X, zi4.Y), fun.Polar(new Vector2(zi4.X, zi4.Y), Pus.AngleOnP(zi4, zii4) + pi / 180, 1)), offset + h1 * kscale, "αn=0°", dimensionStyle);
            else
                Pus.NeedleDim(dxf, new Line(zi4, zii4), new Line(new Vector2(zi4.X, zi4.Y), fun.Polar(new Vector2(zi4.X, zi4.Y), Pus.AngleOnP(zi4, zii4) + alphan, 1)), offset + h1 * kscale, "αn=" + Math.Round(alphan * 180 / pi, 2) + "°", dimensionStyle);
            //图框
            if (Convert.ToDouble(data["isframe"]) == 1)
            {
                Vector2 c4c = new Vector2((b2.X + zb3.X) / 2, (b2.Y + mu1.Y) / 2);
                Dictionary<string, Vector2> positions = Frame.frameA3X(dxf, new Vector2(c4c.X - 420 / 2, c4c.Y + 297 / 2), new Dictionary<string, object>());
                fun.writetextofC(dxf, kscale + ":1", positions["比例"], 3.5, 0, 0.6, 3);
            }

            dxf.DrawingVariables.AcadVer = DxfVersion.AutoCad2007;
            dxf.Save(path);
        }
        public static void StyleB_InsertS(Dictionary<string, Object> data)
        {

            DxfDocument dxf = new DxfDocument();
            Layer contour = new Layer("contour") { Color = AciColor.Cyan };    //1,轮廓层
            Layer cutting = new Layer("cutting") { Color = AciColor.Red };    //切削层

            string path = Convert.ToString(data["path"]);
            double pi = Math.PI;
            //参数名称取自ISO 5610-2
            double b = 8;
            double l1 = 70;
            double l2 = 12;
            double f = 7;
            double insertAngle = 90 * pi / 180;
            double l3 = 6.4;
            double h2 = 8;
            double h1 = 8;
            double s = 2.38;
            double alphan = 7 * pi / 180;
            double cutagl = 75 * pi / 180;
            double lambdas = 0;
            double gamao = 0;
            double repsilon = 0;
            #region
            try
            {
                if (data["re"] != null)
                    repsilon = Convert.ToDouble(data["re"]);
                if (repsilon <= 0)
                    repsilon = 0.01;
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["lams"] != null)
                    lambdas = Math.Abs(Convert.ToDouble(data["lams"]) * pi / 180);
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["gamo"] != null)
                    gamao = Math.Abs(Convert.ToDouble(data["gamo"]) * pi / 180);
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["b"] != null)
                    b = Convert.ToDouble(data["b"]);
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["s"] != null)
                    s = Convert.ToDouble(data["s"]);
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["lf"] != null)
                    l1 = Convert.ToDouble(data["lf"]);
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["lh"] != null)
                    l2 = Convert.ToDouble(data["lh"]);
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["wf"] != null)
                    f = Convert.ToDouble(data["wf"]);
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["h"] != null)
                    h2 = Convert.ToDouble(data["h"]);
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["hf"] != null)
                    h1 = Convert.ToDouble(data["hf"]);
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["epsr"] != null)
                    insertAngle = Convert.ToDouble(data["epsr"]) * pi / 180;
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["kapr"] != null)
                    cutagl = Convert.ToDouble(data["kapr"]) * pi / 180;
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["an"] != null)
                    alphan = Convert.ToDouble(data["an"]) * pi / 180;
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["ic"] != null)
                    l3 = Pus.GetLByIC(Convert.ToDouble(data["ic"]), insertAngle);
            }
            catch (KeyNotFoundException) { }
            #endregion
            double kscale = 1;
            if (l1 >= 120)
                kscale = 1;
            else
                kscale = 1.5;
            double lineWidth = 1;
            //k点位置恒定
            Vector3 k = new Vector3(0, 0, 0);
            Vector3 b2 = new Vector3(k.X + l1, k.Y + f, k.Z - h1);
            Vector3 b1 = new Vector3(b2.X, b2.Y - b, b2.Z);
            Vector3 b6 = new Vector3(k.X + l2, b1.Y, b1.Z);

            //刀杆顶面
            Vector3 u1 = new Vector3(b1.X, b1.Y, b1.Z + h2);
            Vector3 u2 = new Vector3(b2.X, b2.Y, b2.Z + h2);
            Vector3 u3 = new Vector3(b6.X, b2.Y, b2.Z + h2);
            double guai = kscale;
            Vector3 u3p = new Vector3(u3.X - guai, u3.Y, u3.Z);
            Vector3 u4 = new Vector3(b6.X, b6.Y, b6.Z + h2);
            Vector3 u4p = new Vector3(u4.X - guai, u4.Y, u4.Z);

            //横向进给，小于90
            Vector2 twoi4 = fun.Polar(Vector2.Zero, cutagl + pi / 2, repsilon / Math.Tan(insertAngle / 2) - repsilon / Math.Tan((pi - cutagl) / 2));
            Vector2[] twois = Pus.DiamondPoints(twoi4, l3, insertAngle, true, cutagl);
            Vector2 twoi1 = twois[1];
            Vector2 twoi2 = twois[2];
            Vector2 twoi3 = twois[3];
            double theoffset = Math.Tan(alphan) * s;
            Vector2[] twoiis = Pus.OffsetPoints(theoffset, twois);
            Vector2 twoii4 = twoiis[0];
            Vector2 twoii3 = twoiis[3];
            Vector2 twoii1 = twoiis[1];
            Vector2 twoii2 = twoiis[2];

            //刀头面
            Vector3 i4 = new Vector3(twoi4.X, twoi4.Y, k.Z);
            Vector3 i3 = new Vector3(twoi3.X, twoi3.Y, k.Z);
            Vector3 i2 = new Vector3(twoi2.X, twoi2.Y, k.Z);
            Vector3 i1 = new Vector3(twoi1.X, twoi1.Y, k.Z);
            Vector2 cnm = Pus.IntersOnP(i1, new Vector3(i1.X + 1, i1.Y, i1.Z), u3p, u4p);
            Vector3 dt1 = new Vector3(cnm.X, cnm.Y, u4.Z);
            Vector3 dt2 = u3p;
            Vector2 xx = Pus.IntersOnP(i3, i4, u2, u3);
            Vector3 dt4 = Pus.KPoint(i3, new Vector3(xx.X, xx.Y, u3.Z), 0.7);
            Vector3 dt3 = Pus.KPoint(u3, new Vector3(xx.X, xx.Y, u3.Z), 0.85);

            Vector3 bdt1 = new Vector3(dt1.X, dt1.Y, b1.Z);
            Vector3 b5 = new Vector3(twoii4.X, twoii4.Y, b1.Z);
            Vector3 b4 = new Vector3(dt4.X, dt4.Y, b1.Z);
            Vector3 b3 = new Vector3(dt3.X, dt3.Y, b1.Z);

            Vector3 ii4 = new Vector3(twoii4.X, twoii4.Y, k.Z - s);
            Vector3 ii3 = new Vector3(twoii3.X, twoii3.Y, k.Z - s);
            Vector3 ii1 = new Vector3(twoii1.X, twoii1.Y, k.Z - s);
            Vector3 ii2 = new Vector3(twoii2.X, twoii2.Y, k.Z - s);

            i4 = Pus.LinearTrans(kscale, i4);
            i3 = Pus.LinearTrans(kscale, i3);
            i2 = Pus.LinearTrans(kscale, i2);
            i1 = Pus.LinearTrans(kscale, i1);
            dt1 = Pus.LinearTrans(kscale, dt1);
            dt2 = Pus.LinearTrans(kscale, dt2);
            dt3 = Pus.LinearTrans(kscale, dt3);
            dt4 = Pus.LinearTrans(kscale, dt4);

            ii4 = Pus.LinearTrans(kscale, ii4);
            ii3 = Pus.LinearTrans(kscale, ii3);
            ii2 = Pus.LinearTrans(kscale, ii2);
            ii1 = Pus.LinearTrans(kscale, ii1);

            b1 = Pus.LinearTrans(kscale, b1);
            b2 = Pus.LinearTrans(kscale, b2);
            b3 = Pus.LinearTrans(kscale, b3);
            b4 = Pus.LinearTrans(kscale, b4);
            b5 = Pus.LinearTrans(kscale, b5);
            b6 = Pus.LinearTrans(kscale, b6);
            bdt1 = Pus.LinearTrans(kscale, bdt1);

            u1 = Pus.LinearTrans(kscale, u1);
            u2 = Pus.LinearTrans(kscale, u2);
            u3 = Pus.LinearTrans(kscale, u3);
            u3p = Pus.LinearTrans(kscale, u3p);
            u4 = Pus.LinearTrans(kscale, u4);


            //主视图
            LwPolyline mshank = Pus.AddPointsToLwPolyLine(u1, u2, u3, u4);
            mshank.IsClosed = true;
            fun.PolyFill(dxf, mshank, lineWidth, contour);

            LwPolyline minsert = Pus.AddPointsToLwPolyLine(i4, i1, i2, i3);
            minsert.IsClosed = true;
            Pus.AglToArc(minsert, repsilon);

            LwPolyline mhead = Pus.AddPointsToLwPolyLine(i3, i2, i1, dt1, dt2, dt3, dt4, i3);
            mhead.IsClosed = true;
            fun.PolyFill(dxf, mhead, lineWidth, contour);
            LwPolyline mheadc1 = Pus.AddPointsToLwPolyLine(dt1, u4);
            fun.PolyFill(dxf, mheadc1, lineWidth, contour);
            LwPolyline mheadc2 = Pus.AddPointsToLwPolyLine(dt2, u3);
            fun.PolyFill(dxf, mheadc2, lineWidth, contour);

            fun.PolyFill(dxf, minsert, lineWidth, cutting);
            //m视图标注
            DimensionStyle dimensionStyle = new DimensionStyle("mystyle");
            dimensionStyle.ArrowSize = kscale * 1.2;
            dimensionStyle.DimArrow1 = DimensionArrowhead.Closedfilled;
            dimensionStyle.DimArrow2 = DimensionArrowhead.Closedfilled;
            dimensionStyle.TextHeight = kscale;
            dimensionStyle.TextOffset = kscale / 2;
            double offset = 7 * kscale;
            LinearDimension dim_f = new LinearDimension(new Line(new Vector2(k.X, k.Y), new Vector2(b3.X, b3.Y)), offset * 1.5, Pus.Degree(b1, b2), dimensionStyle);
            fun.dxflinedim(dxf, dim_f, f);
            LinearDimension dim_l1 = new LinearDimension(new Line(new Vector2(k.X, k.Y), new Vector2(b1.X, b1.Y)), offset * 1.5, Pus.Degree(new Vector2(b1.X, b1.Y), new Vector2(b6.X, b6.Y)), dimensionStyle);
            fun.dxflinedim(dxf, dim_l1, l1);
            LinearDimension dim_l2 = new LinearDimension(new Line(new Vector2(k.X, k.Y), new Vector2(u4.X, u4.Y)), offset, Pus.Degree(new Vector2(u1.X, u1.Y), new Vector2(u4.X, u4.Y)), dimensionStyle);
            fun.dxflinedim(dxf, dim_l2, l2);
            //LinearDimension dim_l3 = new LinearDimension(new Line(i2, i3), offset, Pus.Degree(new Vector2(i3.X, i3.Y), new Vector2(i2.X, i2.Y)), dimensionStyle);
            //fun.dxflinedim(dxf, dim_l3, Math.Round(l3, 2));
            LinearDimension dim_b = new LinearDimension(new Line(new Vector2(u1.X, u1.Y), new Vector2(u2.X, u2.Y)), offset, Pus.Degree(new Vector2(u2.X, u2.Y), new Vector2(u1.X, u1.Y)), dimensionStyle);
            fun.dxflinedim(dxf, dim_b, b);
            //Angular2LineDimension dim_insertAgl = new Angular2LineDimension(new Line(i4, i3), new Line(i4, i1), offset * 0.5, dimensionStyle);
            //dim_insertAgl.UserText = Math.Round(insertAngle * 180 / pi, 2) + "°";
            //dxf.AddEntity(dim_insertAgl);
            Angular2LineDimension dim_cutagl = new Angular2LineDimension(new Line(i4, i1), new Line(new Vector2(i4.X, i4.Y), fun.Polar(new Vector2(i4.X, i4.Y), -pi / 2, 1)), offset * 0.4, dimensionStyle);
            dim_cutagl.UserText = Math.Round(cutagl * 180 / pi, 2) + "°";
            dxf.AddEntity(dim_cutagl);
            //RadialDimension dim_repsilon = new RadialDimension(Pus.GetArcFromPline(minsert, 1), Pus.Degree(i3, i4) - 10, offset * 0.5, dimensionStyle);
            //dim_repsilon.UserText = "rε=" + repsilon;
            //dxf.AddEntity(dim_repsilon);
            //放倒(所有点)尚未平移到下方，因为只能绕着原点k所在轴旋转
            Vector3 rotate = new Vector3(-1, 0, 0);
            double rotateAgl = pi / 2;
            i4 = Pus.Rodrigue(rotate, 1, rotateAgl, i4);
            i3 = Pus.Rodrigue(rotate, 1, rotateAgl, i3);
            i2 = Pus.Rodrigue(rotate, 1, rotateAgl, i2);
            i1 = Pus.Rodrigue(rotate, 1, rotateAgl, i1);
            dt1 = Pus.Rodrigue(rotate, 1, rotateAgl, dt1);
            dt2 = Pus.Rodrigue(rotate, 1, rotateAgl, dt2);
            dt3 = Pus.Rodrigue(rotate, 1, rotateAgl, dt3);
            dt4 = Pus.Rodrigue(rotate, 1, rotateAgl, dt4);
            ii4 = Pus.Rodrigue(rotate, 1, rotateAgl, ii4);
            ii3 = Pus.Rodrigue(rotate, 1, rotateAgl, ii3);
            ii2 = Pus.Rodrigue(rotate, 1, rotateAgl, ii2);
            ii1 = Pus.Rodrigue(rotate, 1, rotateAgl, ii1);

            b1 = Pus.Rodrigue(rotate, 1, rotateAgl, b1);
            b2 = Pus.Rodrigue(rotate, 1, rotateAgl, b2);
            b3 = Pus.Rodrigue(rotate, 1, rotateAgl, b3);
            b4 = Pus.Rodrigue(rotate, 1, rotateAgl, b4);
            b5 = Pus.Rodrigue(rotate, 1, rotateAgl, b5);
            b6 = Pus.Rodrigue(rotate, 1, rotateAgl, b6);
            bdt1 = Pus.Rodrigue(rotate, 1, rotateAgl, bdt1);

            u1 = Pus.Rodrigue(rotate, 1, rotateAgl, u1);
            u2 = Pus.Rodrigue(rotate, 1, rotateAgl, u2);
            u3 = Pus.Rodrigue(rotate, 1, rotateAgl, u3);
            u3p = Pus.Rodrigue(rotate, 1, rotateAgl, u3p);
            u4 = Pus.Rodrigue(rotate, 1, rotateAgl, u4);

            //创建lambds
            rotate = new Vector3(Math.Sin(cutagl - pi / 2), k.Z, Math.Cos(cutagl - pi / 2));
            rotateAgl = lambdas;
            i4 = Pus.Rodrigue(rotate, 1, rotateAgl, i4);
            i3 = Pus.Rodrigue(rotate, 1, rotateAgl, i3);
            i2 = Pus.Rodrigue(rotate, 1, rotateAgl, i2);
            i1 = Pus.Rodrigue(rotate, 1, rotateAgl, i1);
            ii4 = Pus.Rodrigue(rotate, 1, rotateAgl, ii4);
            ii3 = Pus.Rodrigue(rotate, 1, rotateAgl, ii3);
            ii2 = Pus.Rodrigue(rotate, 1, rotateAgl, ii2);
            ii1 = Pus.Rodrigue(rotate, 1, rotateAgl, ii1);
            dt1 = Pus.Rodrigue(rotate, 1, rotateAgl, dt1);
            dt2 = Pus.Rodrigue(rotate, 1, rotateAgl, dt2);
            dt3 = Pus.Rodrigue(rotate, 1, rotateAgl, dt3);
            dt4 = Pus.Rodrigue(rotate, 1, rotateAgl, dt4);

            //创建gamo
            double disi1_i4 = Vector3.Distance(i1, i4);
            rotate = (i1 - i4) / disi1_i4;
            rotateAgl = gamao;
            i4 = Pus.Rodrigue(rotate, 1, rotateAgl, i4);
            i3 = Pus.Rodrigue(rotate, 1, rotateAgl, i3);
            i2 = Pus.Rodrigue(rotate, 1, rotateAgl, i2);
            i1 = Pus.Rodrigue(rotate, 1, rotateAgl, i1);
            ii4 = Pus.Rodrigue(rotate, 1, rotateAgl, ii4);
            ii3 = Pus.Rodrigue(rotate, 1, rotateAgl, ii3);
            ii2 = Pus.Rodrigue(rotate, 1, rotateAgl, ii2);
            ii1 = Pus.Rodrigue(rotate, 1, rotateAgl, ii1);
            dt1 = Pus.Rodrigue(rotate, 1, rotateAgl, dt1);
            dt2 = Pus.Rodrigue(rotate, 1, rotateAgl, dt2);
            dt3 = Pus.Rodrigue(rotate, 1, rotateAgl, dt3);
            dt4 = Pus.Rodrigue(rotate, 1, rotateAgl, dt4);

            //重新计算刀头的点
            Face3d face4dt = new Face3d(dt2, dt3, dt4);
            Vector3 v4dt = u2 - b2;
            dt1 = Pus.Inters(face4dt, new Line(bdt1, bdt1 + v4dt));
            dt2 = Pus.Inters(face4dt, new Line(u3p, u3p + v4dt));
            dt3 = Pus.Inters(face4dt, new Line(b3, b3 + v4dt));
            dt4 = Pus.Inters(face4dt, new Line(b4, b4 + v4dt));

            Face3d face4buttom = new Face3d(b1, b2, b3);
            b5 = Pus.Inters(face4buttom, new Line(ii4, ii4 + v4dt));
            Vector3 bx = Pus.Inters(face4buttom, new Line(ii1, ii1 + v4dt));
            bdt1 = Pus.Inters(face4buttom, new Line(dt1, dt1 + v4dt));

            //平移所有点到下方
            Vector3 voff = new Vector3(0, -b * kscale - offset * 1.5, 0);
            Vector3 mk = Pus.OffsetXY(voff, k);
            Vector3 mi4 = Pus.OffsetXY(voff, i4);
            Vector3 mi3 = Pus.OffsetXY(voff, i3);
            Vector3 mi2 = Pus.OffsetXY(voff, i2);
            Vector3 mi1 = Pus.OffsetXY(voff, i1);
            Vector3 mdt1 = Pus.OffsetXY(voff, dt1);
            Vector3 mdt2 = Pus.OffsetXY(voff, dt2);
            Vector3 mdt3 = Pus.OffsetXY(voff, dt3);
            Vector3 mdt4 = Pus.OffsetXY(voff, dt4);
            Vector3 mii4 = Pus.OffsetXY(voff, ii4);
            Vector3 mii3 = Pus.OffsetXY(voff, ii3);
            Vector3 mii2 = Pus.OffsetXY(voff, ii2);
            Vector3 mii1 = Pus.OffsetXY(voff, ii1);

            Vector3 mb1 = Pus.OffsetXY(voff, b1);
            Vector3 mb2 = Pus.OffsetXY(voff, b2);
            Vector3 mb3 = Pus.OffsetXY(voff, b3);
            Vector3 mb4 = Pus.OffsetXY(voff, b4);
            Vector3 mb5 = Pus.OffsetXY(voff, b5);
            Vector3 mb6 = Pus.OffsetXY(voff, b6);
            Vector3 mbx = Pus.OffsetXY(voff, bx);
            Vector3 mbdt1 = Pus.OffsetXY(voff, bdt1);

            Vector3 mu1 = Pus.OffsetXY(voff, u1);
            Vector3 mu2 = Pus.OffsetXY(voff, u2);
            Vector3 mu3 = Pus.OffsetXY(voff, u3);
            Vector3 mu4 = Pus.OffsetXY(voff, u4);

            LwPolyline lshank = Pus.AddPointsToLwPolyLine(mb1, mu1, mu4, mb6);
            lshank.IsClosed = true;
            fun.PolyFill(dxf, lshank, lineWidth, contour);
            LwPolyline lshank_dt = Pus.AddPointsToLwPolyLine(mdt1, mu4);
            fun.PolyFill(dxf, lshank_dt, lineWidth, contour);
            LwPolyline lshank_dt1 = Pus.AddPointsToLwPolyLine(mdt2, mu3);
            fun.PolyFill(dxf, lshank_dt1, lineWidth, contour);

            LwPolyline lhead = Pus.AddPointsToLwPolyLine(mii4, mb5, mbdt1, mdt1);
            fun.PolyFill(dxf, lhead, lineWidth, contour);
            LwPolyline lhead1 = Pus.AddPointsToLwPolyLine(mbdt1, mb6);
            fun.PolyFill(dxf, lhead1, lineWidth, contour);
            LwPolyline lhead2 = Pus.AddPointsToLwPolyLine(mdt1, mi1);
            fun.PolyFill(dxf, lhead2, lineWidth, contour);
            LwPolyline lhead3 = Pus.AddPointsToLwPolyLine(mdt1, mbdt1);
            fun.PolyFill(dxf, lhead3, lineWidth, contour);
            LwPolyline lhead4 = Pus.AddPointsToLwPolyLine(mbx, mii1);
            fun.PolyFill(dxf, lhead4, lineWidth, contour);
            if (gamao > 0)
            {
                LwPolyline lheadu = Pus.AddPointsToLwPolyLine(mi1, mdt1, mdt2, mdt3, mdt4, mi3);
                fun.PolyFill(dxf, lheadu, lineWidth, contour);

                LwPolyline linsertu = Pus.AddPointsToLwPolyLine(mi4, mi1, mi2, mi3);
                linsertu.IsClosed = true;
                fun.PolyFill(dxf, linsertu, lineWidth, cutting);
            }

            LwPolyline linsertf = Pus.AddPointsToLwPolyLine(mi4, mii4, mii1, mi1);
            linsertf.IsClosed = true;
            fun.PolyFill(dxf, linsertf, lineWidth, cutting);
            //l视图标注
            LinearDimension dim_h1 = new LinearDimension(new Line(new Vector2(mk.X, mk.Y), new Vector2(mb5.X, mb5.Y)), offset * 0.5, Pus.Degree(b1, u1), dimensionStyle);
            fun.dxflinedim(dxf, dim_h1, h1);
            LinearDimension dim_h2 = new LinearDimension(new Line(new Vector2(mu1.X, mu1.Y), new Vector2(mb1.X, mb1.Y)), offset, Pus.Degree(u1, b1), dimensionStyle);
            fun.dxflinedim(dxf, dim_h2, h2);
            if (lambdas == 0)
                Pus.NeedleDim(dxf, new Line(new Vector2(mi4.X, mi4.Y), fun.Polar(new Vector2(mi4.X, mi4.Y), pi / 180, 1)), new Line(mi4, mi4 + mu4 - mu2), kscale * offset, "λs=0°", dimensionStyle);
            else
                Pus.NeedleDim(dxf, new Line(mi4, mi1), new Line(mi4, mi4 + mu4 - mu2), kscale * offset, "λs=" + Math.Round(lambdas * 180 / pi, 2) + "°", dimensionStyle);
            //左视图
            //所有点移动到原点
            //立正
            rotate = new Vector3(1, 0, 0);
            rotateAgl = pi / 2;
            Vector3 zi4 = Pus.Rodrigue(rotate, 1, rotateAgl, i4);
            Vector3 zi3 = Pus.Rodrigue(rotate, 1, rotateAgl, i3);
            Vector3 zi2 = Pus.Rodrigue(rotate, 1, rotateAgl, i2);
            Vector3 zi1 = Pus.Rodrigue(rotate, 1, rotateAgl, i1);
            Vector3 zdt1 = Pus.Rodrigue(rotate, 1, rotateAgl, dt1);
            Vector3 zdt2 = Pus.Rodrigue(rotate, 1, rotateAgl, dt2);
            Vector3 zdt3 = Pus.Rodrigue(rotate, 1, rotateAgl, dt3);
            Vector3 zdt4 = Pus.Rodrigue(rotate, 1, rotateAgl, dt4);

            Vector3 zii4 = Pus.Rodrigue(rotate, 1, rotateAgl, ii4);
            Vector3 zii3 = Pus.Rodrigue(rotate, 1, rotateAgl, ii3);
            Vector3 zii2 = Pus.Rodrigue(rotate, 1, rotateAgl, ii2);
            Vector3 zii1 = Pus.Rodrigue(rotate, 1, rotateAgl, ii1);

            Vector3 zb1 = Pus.Rodrigue(rotate, 1, rotateAgl, b1);
            Vector3 zb2 = Pus.Rodrigue(rotate, 1, rotateAgl, b2);
            Vector3 zb3 = Pus.Rodrigue(rotate, 1, rotateAgl, b3);
            Vector3 zb4 = Pus.Rodrigue(rotate, 1, rotateAgl, b4);
            Vector3 zb5 = Pus.Rodrigue(rotate, 1, rotateAgl, b5);
            Vector3 zb6 = Pus.Rodrigue(rotate, 1, rotateAgl, b6);
            Vector3 zbx = Pus.Rodrigue(rotate, 1, rotateAgl, bx);
            Vector3 zbdt1 = Pus.Rodrigue(rotate, 1, rotateAgl, bdt1);

            Vector3 zu1 = Pus.Rodrigue(rotate, 1, rotateAgl, u1);
            Vector3 zu2 = Pus.Rodrigue(rotate, 1, rotateAgl, u2);
            Vector3 zu3 = Pus.Rodrigue(rotate, 1, rotateAgl, u3);
            Vector3 zu4 = Pus.Rodrigue(rotate, 1, rotateAgl, u4);

            //绕y转，露出左面
            rotate = new Vector3(0, 1, 0);
            rotateAgl = pi / 2;
            zi4 = Pus.Rodrigue(rotate, 1, rotateAgl, zi4);
            zi3 = Pus.Rodrigue(rotate, 1, rotateAgl, zi3);
            zi2 = Pus.Rodrigue(rotate, 1, rotateAgl, zi2);
            zi1 = Pus.Rodrigue(rotate, 1, rotateAgl, zi1);
            zdt1 = Pus.Rodrigue(rotate, 1, rotateAgl, zdt1);
            zdt2 = Pus.Rodrigue(rotate, 1, rotateAgl, zdt2);
            zdt3 = Pus.Rodrigue(rotate, 1, rotateAgl, zdt3);
            zdt4 = Pus.Rodrigue(rotate, 1, rotateAgl, zdt4);

            zii4 = Pus.Rodrigue(rotate, 1, rotateAgl, zii4);
            zii3 = Pus.Rodrigue(rotate, 1, rotateAgl, zii3);
            zii2 = Pus.Rodrigue(rotate, 1, rotateAgl, zii2);
            zii1 = Pus.Rodrigue(rotate, 1, rotateAgl, zii1);

            zb1 = Pus.Rodrigue(rotate, 1, rotateAgl, zb1);
            zb2 = Pus.Rodrigue(rotate, 1, rotateAgl, zb2);
            zb3 = Pus.Rodrigue(rotate, 1, rotateAgl, zb3);
            zb4 = Pus.Rodrigue(rotate, 1, rotateAgl, zb4);
            zb5 = Pus.Rodrigue(rotate, 1, rotateAgl, zb5);
            zb6 = Pus.Rodrigue(rotate, 1, rotateAgl, zb6);
            zbx = Pus.Rodrigue(rotate, 1, rotateAgl, zbx);
            zbdt1 = Pus.Rodrigue(rotate, 1, rotateAgl, zbdt1);

            zu1 = Pus.Rodrigue(rotate, 1, rotateAgl, zu1);
            zu2 = Pus.Rodrigue(rotate, 1, rotateAgl, zu2);
            zu3 = Pus.Rodrigue(rotate, 1, rotateAgl, zu3);
            zu4 = Pus.Rodrigue(rotate, 1, rotateAgl, zu4);

            //平移
            voff = new Vector3(-b * kscale - offset * 2, 0, 0);
            zi4 = Pus.OffsetXY(voff, zi4);
            zi3 = Pus.OffsetXY(voff, zi3);
            zi2 = Pus.OffsetXY(voff, zi2);
            zi1 = Pus.OffsetXY(voff, zi1);
            zdt1 = Pus.OffsetXY(voff, zdt1);
            zdt2 = Pus.OffsetXY(voff, zdt2);
            zdt3 = Pus.OffsetXY(voff, zdt3);
            zdt4 = Pus.OffsetXY(voff, zdt4);

            zii4 = Pus.OffsetXY(voff, zii4);
            zii3 = Pus.OffsetXY(voff, zii3);
            zii2 = Pus.OffsetXY(voff, zii2);
            zii1 = Pus.OffsetXY(voff, zii1);

            zb1 = Pus.OffsetXY(voff, zb1);
            zb2 = Pus.OffsetXY(voff, zb2);
            zb3 = Pus.OffsetXY(voff, zb3);
            zb4 = Pus.OffsetXY(voff, zb4);
            zb5 = Pus.OffsetXY(voff, zb5);
            zb6 = Pus.OffsetXY(voff, zb6);
            zbx = Pus.OffsetXY(voff, zbx);
            zbdt1 = Pus.OffsetXY(voff, zbdt1);

            zu1 = Pus.OffsetXY(voff, zu1);
            zu2 = Pus.OffsetXY(voff, zu2);
            zu3 = Pus.OffsetXY(voff, zu3);
            zu4 = Pus.OffsetXY(voff, zu4);

            //左视图绘制
            LwPolyline zshank = Pus.AddPointsToLwPolyLine(zii4, zb5, zb4, zb3, zdt3, zdt4, zi3);
            fun.PolyFill(dxf, zshank, lineWidth, contour);
            LwPolyline zshank2 = Pus.AddPointsToLwPolyLine(zb4, zdt4);
            fun.PolyFill(dxf, zshank2, lineWidth, contour);
            if (lambdas > 0)
            {
                LwPolyline zshank1 = Pus.AddPointsToLwPolyLine(zdt3, zdt2, zdt1, zi1);
                fun.PolyFill(dxf, zshank1, lineWidth, contour);

                LwPolyline zinsert = Pus.AddPointsToLwPolyLine(zi4, zi1, zi2, zi3);
                zinsert.IsClosed = true;
                fun.PolyFill(dxf, zinsert, lineWidth, cutting);
            }

            LwPolyline zlen1 = Pus.AddPointsToLwPolyLine(zi3, zii3, zii4, zi4);
            zlen1.IsClosed = true;
            fun.PolyFill(dxf, zlen1, lineWidth, cutting);

            if (cutagl < pi / 2)
            {
                LwPolyline zlen2 = Pus.AddPointsToLwPolyLine(zii4, zii1, zi1, zi4);
                fun.PolyFill(dxf, zlen2, lineWidth, cutting);
            }
            //if (zdt1.Y > zu4.Y)
            //{
            //    Vector2 visible = Pus.IntersOnP(zi4, zi1, zb4, zu4);
            //    LwPolyline visiLine = Pus.AddPointsToLwPolyLine(zdt1, zu4);
            //    Pus.AddPointsToLwPolyLine(visiLine, visible);
            //    fun.PolyFill(dxf, visiLine, lineWidth, contour);
            //}
            //左视图标注
            //刃倾角
            if (gamao == 0)
                Pus.NeedleDim(dxf, new Line(new Vector2(zi4.X, zi4.Y), fun.Polar(new Vector2(zi4.X, zi4.Y), Pus.AngleOnP(zi3, zi4) + pi / 180, 1)), new Line(zi3, zi4), offset * 1.5, "γo=0°", dimensionStyle);
            else
                Pus.NeedleDim(dxf, new Line(zi3, zi4), new Line(new Vector2(zi4.X, zi4.Y), fun.Polar(new Vector2(zi4.X, zi4.Y), Pus.AngleOnP(zi3, zi4) + gamao, 1)), offset * 1.5, "γo=" + Math.Round(lambdas * 180 / pi, 2) + "°", dimensionStyle);

            //LinearDimension dim_s = new LinearDimension(new Line(zi4, zii4), offset, Pus.Degree(zi4, zi3) + 90, dimensionStyle);
            //fun.dxflinedim(dxf, dim_s, s);

            //后角
            if (alphan == 0)
                Pus.NeedleDim(dxf, new Line(zi4, zii4), new Line(new Vector2(zi4.X, zi4.Y), fun.Polar(new Vector2(zi4.X, zi4.Y), Pus.AngleOnP(zi4, zii4) + pi / 180, 1)), offset + h1 * kscale, "αn=0°", dimensionStyle);
            else
                Pus.NeedleDim(dxf, new Line(zi4, zii4), new Line(new Vector2(zi4.X, zi4.Y), fun.Polar(new Vector2(zi4.X, zi4.Y), Pus.AngleOnP(zi4, zii4) + alphan, 1)), offset + h1 * kscale, "αn=" + Math.Round(alphan * 180 / pi, 2) + "°", dimensionStyle);
            //图框
            if (Convert.ToDouble(data["isframe"]) == 1)
            {
                Vector2 c4c = new Vector2((b2.X + zb3.X) / 2, (b2.Y + mu1.Y) / 2);
                Dictionary<string, Vector2> positions = Frame.frameA3X(dxf, new Vector2(c4c.X - 420 / 2, c4c.Y + 297 / 2), new Dictionary<string, object>());
                fun.writetextofC(dxf, kscale + ":1", positions["比例"], 3.5, 0, 0.6, 3);
            }

            dxf.DrawingVariables.AcadVer = DxfVersion.AutoCad2007;
            dxf.Save(path);
        }
        //F型刀头 纵大跨
        public static void StyleF_InsertC(Dictionary<string, Object> data)
        {

            DxfDocument dxf = new DxfDocument();
            Layer contour = new Layer("contour") { Color = AciColor.Cyan };    //1,轮廓层
            Layer cutting = new Layer("cutting") { Color = AciColor.Cyan };    //附加线

            string path = Convert.ToString(data["path"]);
            //参数名称取自ISO 5610-2
            double b = 8;
            double l1 = 70;
            double l2 = 12;
            double f = 10;
            double insertAngle = 80 * pi / 180;
            double l3 = 6.4;
            double h2 = 8;
            double h1 = 8;
            double s = 2.38;
            double alphan = 7 * pi / 180;
            double cutagl = 90 * pi / 180;
            double lambdas = 0;
            double gamao = 0;
            double repsilon = 0;
            #region
            try
            {
                if (data["re"] != null)
                    repsilon = Convert.ToDouble(data["re"]);
                if (repsilon <= 0)
                    repsilon = 0.01;
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["lams"] != null)
                    lambdas = Convert.ToDouble(data["lams"]) * pi / 180;
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["gamo"] != null)
                    gamao = Convert.ToDouble(data["gamo"]) * pi / 180;
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["b"] != null)
                    b = Convert.ToDouble(data["b"]);
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["s"] != null)
                    s = Convert.ToDouble(data["s"]);
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["lf"] != null)
                    l1 = Convert.ToDouble(data["lf"]);
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["lh"] != null)
                    l2 = Convert.ToDouble(data["lh"]);
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["wf"] != null)
                    f = Convert.ToDouble(data["wf"]);
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["h"] != null)
                    h2 = Convert.ToDouble(data["h"]);
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["hf"] != null)
                    h1 = Convert.ToDouble(data["hf"]);
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["epsr"] != null)
                    insertAngle = Convert.ToDouble(data["epsr"]) * pi / 180;
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["kapr"] != null)
                    cutagl = Convert.ToDouble(data["kapr"]) * pi / 180;
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["an"] != null)
                    alphan = Convert.ToDouble(data["an"]) * pi / 180;
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["ic"] != null)
                    l3 = Pus.GetLByIC(Convert.ToDouble(data["ic"]), insertAngle);
            }
            catch (KeyNotFoundException) { }
            #endregion
            //线性变换
            Vector2 zero = new Vector2(0, 0);
            double kscale = 1;
            if (l1 >= 120)
                kscale = 1;
            else
                kscale = 1.5;
            double lineWidth = 1;
            //k点位置恒定
            Vector3 k = new Vector3(0, 0, 0);
            Vector3 b2 = new Vector3(k.X + l1, k.Y + f, k.Z - h1);
            Vector3 b1 = new Vector3(b2.X, b2.Y - b, b2.Z);
            Vector3 b6 = new Vector3(k.X + l2, b1.Y, b1.Z);

            //刀杆顶面
            Vector3 u1 = new Vector3(b1.X, b1.Y, b1.Z + h2);
            Vector3 u2 = new Vector3(b2.X, b2.Y, b2.Z + h2);
            Vector3 u3 = new Vector3(b6.X, b2.Y, b2.Z + h2);
            Vector3 u4 = new Vector3(b6.X, b6.Y, b6.Z + h2);

            //前角与刃倾角都为0时刀尖点与k的关系,"纵向进给，主偏角大于90°k点与i4的关系"
            Vector2 cen = fun.Polar(new Vector2(k.X, k.Y), pi / 4, repsilon / Math.Sin(pi / 4));
            Vector2 twoi4 = fun.Polar(cen, 2 * pi - cutagl - insertAngle / 2, repsilon / Math.Sin(insertAngle / 2));
            Vector2[] twois = Pus.DiamondPoints(twoi4, l3, insertAngle, false, cutagl);
            Vector2 twoi1 = twois[1];
            Vector2 twoi2 = twois[2];
            Vector2 twoi3 = twois[3];
            double theoffset = Math.Tan(alphan) * s;
            Vector2[] twoiis = Pus.OffsetPoints(theoffset, twois);
            Vector2 twoii4 = twoiis[0];
            Vector2 twoii3 = twoiis[3];
            Vector2 twoii1 = twoiis[1];
            Vector2 twoii2 = twoiis[2];

            //刀头面
            Vector3 i4 = new Vector3(twoi4.X, twoi4.Y, k.Z);
            Vector3 i3 = new Vector3(twoi3.X, twoi3.Y, k.Z);
            Vector3 i2 = new Vector3(twoi2.X, twoi2.Y, k.Z);
            Vector3 i1 = new Vector3(twoi1.X, twoi1.Y, k.Z);
            Vector3 x1 = Pus.KPoint(i4, i1, 0.15);
            Vector3 dt1 = u4;
            Vector3 dt2 = u3;
            Vector3 dt4 = Pus.KPoint(i4, i3, 1.15);
            Vector3 dt3 = Pus.KPoint(u2, u3, 1.35);

            Vector3 b5 = new Vector3(twoii4.X, twoii4.Y, b1.Z);
            Vector3 b4 = new Vector3(dt4.X, dt4.Y, b1.Z);
            Vector3 b3 = new Vector3(dt3.X, dt3.Y, b1.Z);

            Vector3 ii4 = new Vector3(twoii4.X, twoii4.Y, k.Z - s);
            Vector3 ii3 = new Vector3(twoii3.X, twoii3.Y, k.Z - s);
            Vector3 ii1 = new Vector3(twoii1.X, twoii1.Y, k.Z - s);
            Vector3 ii2 = new Vector3(twoii2.X, twoii2.Y, k.Z - s);

            i4 = Pus.LinearTrans(kscale, i4);
            i3 = Pus.LinearTrans(kscale, i3);
            i2 = Pus.LinearTrans(kscale, i2);
            i1 = Pus.LinearTrans(kscale, i1);
            dt1 = Pus.LinearTrans(kscale, dt1);
            dt2 = Pus.LinearTrans(kscale, dt2);
            dt3 = Pus.LinearTrans(kscale, dt3);
            dt4 = Pus.LinearTrans(kscale, dt4);
            ii4 = Pus.LinearTrans(kscale, ii4);
            ii3 = Pus.LinearTrans(kscale, ii3);
            ii2 = Pus.LinearTrans(kscale, ii2);
            ii1 = Pus.LinearTrans(kscale, ii1);

            b1 = Pus.LinearTrans(kscale, b1);
            b2 = Pus.LinearTrans(kscale, b2);
            b3 = Pus.LinearTrans(kscale, b3);
            b4 = Pus.LinearTrans(kscale, b4);
            b5 = Pus.LinearTrans(kscale, b5);
            b6 = Pus.LinearTrans(kscale, b6);

            u1 = Pus.LinearTrans(kscale, u1);
            u2 = Pus.LinearTrans(kscale, u2);
            u3 = Pus.LinearTrans(kscale, u3);
            u4 = Pus.LinearTrans(kscale, u4);

            //主视图
            LwPolyline mshank = Pus.AddPointsToLwPolyLine(u1, u2, u3, u4);
            mshank.IsClosed = true;
            fun.PolyFill(dxf, mshank, lineWidth, contour);

            LwPolyline minsert = Pus.AddPointsToLwPolyLine(i4, i1, i2, i3);
            minsert.IsClosed = true;
            Pus.AglToArc(minsert, repsilon);
            Vector2 vertex2 = minsert.Vertexes[2].Position;
            Vector2 vertex7 = minsert.Vertexes[7].Position;

            LwPolyline mhead = Pus.AddPointsToLwPolyLine(new Vector3(vertex2.X, vertex2.Y, 0.0), dt1, dt2, dt3, dt4, new Vector3(vertex7.X, vertex7.Y, 0.0));
            fun.PolyFill(dxf, mhead, lineWidth, contour);

            fun.PolyFill(dxf, minsert, lineWidth, cutting);
            //主视图标注
            DimensionStyle dimensionStyle = new DimensionStyle("mystyle");
            dimensionStyle.ArrowSize = 0.2;
            dimensionStyle.DimArrow1 = DimensionArrowhead.Closedfilled;
            dimensionStyle.DimArrow2 = DimensionArrowhead.Closedfilled;
            dimensionStyle.TextHeight = kscale;
            dimensionStyle.TextOffset = kscale / 2;
            double offset = 7 * kscale;
            LinearDimension dim_f = new LinearDimension(new Line(new Vector2(k.X, k.Y), new Vector2(b3.X, b3.Y)), offset, Pus.Degree(b1, b2), dimensionStyle);
            fun.dxflinedim(dxf, dim_f, f);
            LinearDimension dim_l1 = new LinearDimension(new Line(new Vector2(k.X, k.Y), new Vector2(b1.X, b1.Y)), offset, Pus.Degree(new Vector2(b1.X, b1.Y), new Vector2(b6.X, b6.Y)), dimensionStyle);
            fun.dxflinedim(dxf, dim_l1, l1);
            LinearDimension dim_l2 = new LinearDimension(new Line(new Vector2(k.X, k.Y), new Vector2(u4.X, u4.Y)), offset * 0.7, Pus.Degree(new Vector2(u1.X, u1.Y), new Vector2(u4.X, u4.Y)), dimensionStyle);
            fun.dxflinedim(dxf, dim_l2, l2);
            LinearDimension dim_l3 = new LinearDimension(new Line(new Vector2(i1.X, i1.Y), new Vector2(i2.X, i2.Y)), offset * 0.6, Pus.Degree(new Vector2(i2.X, i2.Y), new Vector2(i1.X, i1.Y)), dimensionStyle);
            fun.dxflinedim(dxf, dim_l3, Math.Round(l3, 2));
            LinearDimension dim_b = new LinearDimension(new Line(new Vector2(u1.X, u1.Y), new Vector2(u2.X, u2.Y)), offset, Pus.Degree(new Vector2(u2.X, u2.Y), new Vector2(u1.X, u1.Y)), dimensionStyle);
            fun.dxflinedim(dxf, dim_b, b);
            //Angular2LineDimension dim_insertAgl = new Angular2LineDimension(new Line(i4, i3), new Line(i4, i1), offset * 0.5, dimensionStyle);
            //dim_insertAgl.UserText = Math.Round(insertAngle * 180 / pi, 2) + "°";
            //dxf.AddEntity(dim_insertAgl);
            Angular2LineDimension dim_cutagl = new Angular2LineDimension(new Line(new Vector2(i4.X, i4.Y), new Vector2(i3.X, i3.Y)), new Line(new Vector2(i4.X, i4.Y), fun.Polar(new Vector2(i4.X, i4.Y), pi, 1)), offset * 0.4, dimensionStyle);
            dim_cutagl.UserText = Math.Round(cutagl * 180 / pi, 2) + "°";
            dxf.AddEntity(dim_cutagl);
            RadialDimension dim_repsilon = new RadialDimension(Pus.GetArcFromPline(minsert, 1), Pus.Degree(i3, i4) - 45, offset * 0.5, dimensionStyle);
            dim_repsilon.UserText = "rε=" + repsilon;
            dxf.AddEntity(dim_repsilon);
            //放倒(所有点)尚未平移到下方，因为只能绕着原点k所在轴旋转
            Vector3 rotate = new Vector3(-1, 0, 0);
            double rotateAgl = pi / 2;
            i4 = Pus.Rodrigue(rotate, 1, rotateAgl, i4);
            i3 = Pus.Rodrigue(rotate, 1, rotateAgl, i3);
            i2 = Pus.Rodrigue(rotate, 1, rotateAgl, i2);
            i1 = Pus.Rodrigue(rotate, 1, rotateAgl, i1);
            dt1 = Pus.Rodrigue(rotate, 1, rotateAgl, dt1);
            dt2 = Pus.Rodrigue(rotate, 1, rotateAgl, dt2);
            dt3 = Pus.Rodrigue(rotate, 1, rotateAgl, dt3);
            dt4 = Pus.Rodrigue(rotate, 1, rotateAgl, dt4);
            ii4 = Pus.Rodrigue(rotate, 1, rotateAgl, ii4);
            ii3 = Pus.Rodrigue(rotate, 1, rotateAgl, ii3);
            ii2 = Pus.Rodrigue(rotate, 1, rotateAgl, ii2);
            ii1 = Pus.Rodrigue(rotate, 1, rotateAgl, ii1);

            b1 = Pus.Rodrigue(rotate, 1, rotateAgl, b1);
            b2 = Pus.Rodrigue(rotate, 1, rotateAgl, b2);
            b3 = Pus.Rodrigue(rotate, 1, rotateAgl, b3);
            b4 = Pus.Rodrigue(rotate, 1, rotateAgl, b4);
            b5 = Pus.Rodrigue(rotate, 1, rotateAgl, b5);
            b6 = Pus.Rodrigue(rotate, 1, rotateAgl, b6);

            u1 = Pus.Rodrigue(rotate, 1, rotateAgl, u1);
            u2 = Pus.Rodrigue(rotate, 1, rotateAgl, u2);
            u3 = Pus.Rodrigue(rotate, 1, rotateAgl, u3);
            u4 = Pus.Rodrigue(rotate, 1, rotateAgl, u4);

            //创建lambds
            rotate = new Vector3(Math.Cos(pi - cutagl + pi / 2), Math.Sin(pi - cutagl + pi / 2), k.Z);
            rotateAgl = -lambdas;
            i4 = Pus.Rodrigue(rotate, 1, rotateAgl, i4);
            i3 = Pus.Rodrigue(rotate, 1, rotateAgl, i3);
            i2 = Pus.Rodrigue(rotate, 1, rotateAgl, i2);
            i1 = Pus.Rodrigue(rotate, 1, rotateAgl, i1);
            ii4 = Pus.Rodrigue(rotate, 1, rotateAgl, ii4);
            ii3 = Pus.Rodrigue(rotate, 1, rotateAgl, ii3);
            ii2 = Pus.Rodrigue(rotate, 1, rotateAgl, ii2);
            ii1 = Pus.Rodrigue(rotate, 1, rotateAgl, ii1);
            dt1 = Pus.Rodrigue(rotate, 1, rotateAgl, dt1);
            dt2 = Pus.Rodrigue(rotate, 1, rotateAgl, dt2);
            dt3 = Pus.Rodrigue(rotate, 1, rotateAgl, dt3);
            dt4 = Pus.Rodrigue(rotate, 1, rotateAgl, dt4);

            //创建gamo
            double disi3_i4 = Vector3.Distance(i3, i4);
            rotate = (i3 - i4) / disi3_i4;
            rotateAgl = -gamao;
            i4 = Pus.Rodrigue(rotate, 1, rotateAgl, i4);
            i3 = Pus.Rodrigue(rotate, 1, rotateAgl, i3);
            i2 = Pus.Rodrigue(rotate, 1, rotateAgl, i2);
            i1 = Pus.Rodrigue(rotate, 1, rotateAgl, i1);
            ii4 = Pus.Rodrigue(rotate, 1, rotateAgl, ii4);
            ii3 = Pus.Rodrigue(rotate, 1, rotateAgl, ii3);
            ii2 = Pus.Rodrigue(rotate, 1, rotateAgl, ii2);
            ii1 = Pus.Rodrigue(rotate, 1, rotateAgl, ii1);
            dt1 = Pus.Rodrigue(rotate, 1, rotateAgl, dt1);
            dt2 = Pus.Rodrigue(rotate, 1, rotateAgl, dt2);
            dt3 = Pus.Rodrigue(rotate, 1, rotateAgl, dt3);
            dt4 = Pus.Rodrigue(rotate, 1, rotateAgl, dt4);

            //重新计算刀头的点
            Face3d face4dt = new Face3d(dt2, dt3, dt4);
            Vector3 v4dt = u2 - b2;
            Vector3 u3p = new Vector3(u3.X - 1, u3.Y, u3.Z);
            dt2 = Pus.Inters(face4dt, new Line(u3p, u3p + v4dt));
            dt3 = Pus.Inters(face4dt, new Line(b3, b3 + v4dt));
            dt4 = Pus.Inters(face4dt, new Line(b4, b4 + v4dt));

            Face3d face4buttom = new Face3d(b1, b2, b3);
            b5 = Pus.Inters(face4buttom, new Line(i4, ii4));

            //平移所有点到下方
            Vector3 voff = new Vector3(0, -15 * kscale, 0);
            Vector3 mk = Pus.OffsetXY(voff, k);
            Vector3 mi4 = Pus.OffsetXY(voff, i4);
            Vector3 mi3 = Pus.OffsetXY(voff, i3);
            Vector3 mi2 = Pus.OffsetXY(voff, i2);
            Vector3 mi1 = Pus.OffsetXY(voff, i1);
            Vector3 mdt1 = Pus.OffsetXY(voff, dt1);
            Vector3 mdt2 = Pus.OffsetXY(voff, dt2);
            Vector3 mdt3 = Pus.OffsetXY(voff, dt3);
            Vector3 mdt4 = Pus.OffsetXY(voff, dt4);
            Vector3 mii4 = Pus.OffsetXY(voff, ii4);
            Vector3 mii3 = Pus.OffsetXY(voff, ii3);
            Vector3 mii2 = Pus.OffsetXY(voff, ii2);
            Vector3 mii1 = Pus.OffsetXY(voff, ii1);

            Vector3 mb1 = Pus.OffsetXY(voff, b1);
            Vector3 mb2 = Pus.OffsetXY(voff, b2);
            Vector3 mb3 = Pus.OffsetXY(voff, b3);
            Vector3 mb4 = Pus.OffsetXY(voff, b4);
            Vector3 mb5 = Pus.OffsetXY(voff, b5);
            Vector3 mb6 = Pus.OffsetXY(voff, b6);

            Vector3 mu1 = Pus.OffsetXY(voff, u1);
            Vector3 mu2 = Pus.OffsetXY(voff, u2);
            Vector3 mu3 = Pus.OffsetXY(voff, u3);
            Vector3 mu4 = Pus.OffsetXY(voff, u4);

            LwPolyline lshank = Pus.AddPointsToLwPolyLine(mb1, mu1, mu4, mb6);
            lshank.IsClosed = true;
            fun.PolyFill(dxf, lshank, lineWidth, contour);
            LwPolyline lshank_dt = Pus.AddPointsToLwPolyLine(mdt1, mu4);
            fun.PolyFill(dxf, lshank_dt, lineWidth, contour);

            LwPolyline lhead = Pus.AddPointsToLwPolyLine(mb6, mdt1, mi1, mii1, mii4, mb5);
            lhead.IsClosed = true;
            fun.PolyFill(dxf, lhead, lineWidth, contour);
            LwPolyline lheadu = Pus.AddPointsToLwPolyLine(mi1, mdt1, mdt2, mdt3, mdt4, mi3);
            fun.PolyFill(dxf, lheadu, lineWidth, contour);

            LwPolyline linsertu = Pus.AddPointsToLwPolyLine(mi4, mi1, mi2, mi3);
            linsertu.IsClosed = true;
            fun.PolyFill(dxf, linsertu, lineWidth, cutting);
            LwPolyline linsertf = Pus.AddPointsToLwPolyLine(mi4, mii4, mii1, mi1);
            linsertf.IsClosed = true;
            fun.PolyFill(dxf, linsertf, lineWidth, cutting);
            //m视图标注
            LinearDimension dim_h1 = new LinearDimension(new Line(new Vector2(mk.X, mk.Y), new Vector2(mb5.X, mb5.Y)), offset * 0.3, Pus.Degree(b1, u1), dimensionStyle);
            fun.dxflinedim(dxf, dim_h1, h1);
            LinearDimension dim_h2 = new LinearDimension(new Line(new Vector2(mu1.X, mu1.Y), new Vector2(mb1.X, mb1.Y)), offset, Pus.Degree(u1, b1), dimensionStyle);
            fun.dxflinedim(dxf, dim_h2, h2);
            if (gamao == 0)
                Pus.NeedleDim(dxf, new Line(new Vector2(mi3.X, mi3.Y), fun.Polar(new Vector2(mi3.X, mi3.Y), pi + pi / 180, 1)), new Line(new Vector2(mi2.X, mi2.Y), new Vector2(mi3.X, mi3.Y)), offset, "γo=0°", dimensionStyle);
            else
                Pus.NeedleDim(dxf, new Line(mi2, mi3), new Line(new Vector2(mi3.X, mi3.Y), fun.Polar(new Vector2(mi3.X, mi3.Y), pi, 1)), offset, "γo=" + Math.Round(gamao * 180 / pi, 2) + "°", dimensionStyle);
            //左视图
            //所有点移动到原点
            //立正
            rotate = new Vector3(1, 0, 0);
            rotateAgl = pi / 2;
            Vector3 zi4 = Pus.Rodrigue(rotate, 1, rotateAgl, i4);
            Vector3 zi3 = Pus.Rodrigue(rotate, 1, rotateAgl, i3);
            Vector3 zi2 = Pus.Rodrigue(rotate, 1, rotateAgl, i2);
            Vector3 zi1 = Pus.Rodrigue(rotate, 1, rotateAgl, i1);
            Vector3 zdt1 = Pus.Rodrigue(rotate, 1, rotateAgl, dt1);
            Vector3 zdt2 = Pus.Rodrigue(rotate, 1, rotateAgl, dt2);
            Vector3 zdt3 = Pus.Rodrigue(rotate, 1, rotateAgl, dt3);
            Vector3 zdt4 = Pus.Rodrigue(rotate, 1, rotateAgl, dt4);
            Vector3 zii4 = Pus.Rodrigue(rotate, 1, rotateAgl, ii4);
            Vector3 zii3 = Pus.Rodrigue(rotate, 1, rotateAgl, ii3);
            Vector3 zii2 = Pus.Rodrigue(rotate, 1, rotateAgl, ii2);
            Vector3 zii1 = Pus.Rodrigue(rotate, 1, rotateAgl, ii1);

            Vector3 zb1 = Pus.Rodrigue(rotate, 1, rotateAgl, b1);
            Vector3 zb2 = Pus.Rodrigue(rotate, 1, rotateAgl, b2);
            Vector3 zb3 = Pus.Rodrigue(rotate, 1, rotateAgl, b3);
            Vector3 zb4 = Pus.Rodrigue(rotate, 1, rotateAgl, b4);
            Vector3 zb5 = Pus.Rodrigue(rotate, 1, rotateAgl, b5);
            Vector3 zb6 = Pus.Rodrigue(rotate, 1, rotateAgl, b6);

            Vector3 zu1 = Pus.Rodrigue(rotate, 1, rotateAgl, u1);
            Vector3 zu2 = Pus.Rodrigue(rotate, 1, rotateAgl, u2);
            Vector3 zu3 = Pus.Rodrigue(rotate, 1, rotateAgl, u3);
            Vector3 zu4 = Pus.Rodrigue(rotate, 1, rotateAgl, u4);

            //绕y转，露出左面
            rotate = new Vector3(0, 1, 0);
            rotateAgl = pi / 2;
            zi4 = Pus.Rodrigue(rotate, 1, rotateAgl, zi4);
            zi3 = Pus.Rodrigue(rotate, 1, rotateAgl, zi3);
            zi2 = Pus.Rodrigue(rotate, 1, rotateAgl, zi2);
            zi1 = Pus.Rodrigue(rotate, 1, rotateAgl, zi1);
            zdt1 = Pus.Rodrigue(rotate, 1, rotateAgl, zdt1);
            zdt2 = Pus.Rodrigue(rotate, 1, rotateAgl, zdt2);
            zdt3 = Pus.Rodrigue(rotate, 1, rotateAgl, zdt3);
            zdt4 = Pus.Rodrigue(rotate, 1, rotateAgl, zdt4);
            zii4 = Pus.Rodrigue(rotate, 1, rotateAgl, zii4);
            zii3 = Pus.Rodrigue(rotate, 1, rotateAgl, zii3);
            zii2 = Pus.Rodrigue(rotate, 1, rotateAgl, zii2);
            zii1 = Pus.Rodrigue(rotate, 1, rotateAgl, zii1);

            zb1 = Pus.Rodrigue(rotate, 1, rotateAgl, zb1);
            zb2 = Pus.Rodrigue(rotate, 1, rotateAgl, zb2);
            zb3 = Pus.Rodrigue(rotate, 1, rotateAgl, zb3);
            zb4 = Pus.Rodrigue(rotate, 1, rotateAgl, zb4);
            zb5 = Pus.Rodrigue(rotate, 1, rotateAgl, zb5);
            zb6 = Pus.Rodrigue(rotate, 1, rotateAgl, zb6);

            zu1 = Pus.Rodrigue(rotate, 1, rotateAgl, zu1);
            zu2 = Pus.Rodrigue(rotate, 1, rotateAgl, zu2);
            zu3 = Pus.Rodrigue(rotate, 1, rotateAgl, zu3);
            zu4 = Pus.Rodrigue(rotate, 1, rotateAgl, zu4);

            //平移
            voff = new Vector3(-25 * kscale, 0, 0);
            zi4 = Pus.OffsetXY(voff, zi4);
            zi3 = Pus.OffsetXY(voff, zi3);
            zi2 = Pus.OffsetXY(voff, zi2);
            zi1 = Pus.OffsetXY(voff, zi1);
            zdt1 = Pus.OffsetXY(voff, zdt1);
            zdt2 = Pus.OffsetXY(voff, zdt2);
            zdt3 = Pus.OffsetXY(voff, zdt3);
            zdt4 = Pus.OffsetXY(voff, zdt4);
            zii4 = Pus.OffsetXY(voff, zii4);
            zii3 = Pus.OffsetXY(voff, zii3);
            zii2 = Pus.OffsetXY(voff, zii2);
            zii1 = Pus.OffsetXY(voff, zii1);

            zb1 = Pus.OffsetXY(voff, zb1);
            zb2 = Pus.OffsetXY(voff, zb2);
            zb3 = Pus.OffsetXY(voff, zb3);
            zb4 = Pus.OffsetXY(voff, zb4);
            zb5 = Pus.OffsetXY(voff, zb5);
            zb6 = Pus.OffsetXY(voff, zb6);

            zu1 = Pus.OffsetXY(voff, zu1);
            zu2 = Pus.OffsetXY(voff, zu2);
            zu3 = Pus.OffsetXY(voff, zu3);
            zu4 = Pus.OffsetXY(voff, zu4);

            //左视图绘制
            LwPolyline zshank = Pus.AddPointsToLwPolyLine(zii4, zb5, zb4, zb3, zdt3, zdt4, zi3);
            fun.PolyFill(dxf, zshank, lineWidth, contour);
            LwPolyline zshank2 = Pus.AddPointsToLwPolyLine(zb4, zdt4);
            fun.PolyFill(dxf, zshank2, lineWidth, contour);
            if (gamao > 0)
            {
                LwPolyline zshank1 = Pus.AddPointsToLwPolyLine(zdt3, zdt2, zdt1, zi1);
                fun.PolyFill(dxf, zshank1, lineWidth, contour);

                LwPolyline zinsert = Pus.AddPointsToLwPolyLine(zi4, zi1, zi2, zi3);
                zinsert.IsClosed = true;
                fun.PolyFill(dxf, zinsert, lineWidth, cutting);
            }

            LwPolyline zlen1 = Pus.AddPointsToLwPolyLine(zi3, zii3, zii4, zi4);
            zlen1.IsClosed = true;
            fun.PolyFill(dxf, zlen1, lineWidth, cutting);
            //左视图标注
            //刃倾角
            if (lambdas == 0)
                Pus.NeedleDim(dxf, new Line(new Vector2(zi4.X, zi4.Y), fun.Polar(new Vector2(zi4.X, zi4.Y), pi / 2 + pi / 180, 1)), new Line(zi3, zi4), offset, "λs=0°", dimensionStyle);
            else
                Pus.NeedleDim(dxf, new Line(zi3, zi4), new Line(new Vector2(zi4.X, zi4.Y), fun.Polar(new Vector2(zi4.X, zi4.Y), pi / 2, 1)), offset, "λs=" + Math.Round(lambdas * 180 / pi, 2) + "°", dimensionStyle);
            LinearDimension dim_s = new LinearDimension(new Line(zi4, zii4), offset * 0.7, Pus.Degree(zi4, zi3) + 90, dimensionStyle);
            fun.dxflinedim(dxf, dim_s, s);
            //后角
            if (alphan == 0)
                Pus.NeedleDim(dxf, new Line(new Vector2(zi4.X, zi4.Y), fun.Polar(new Vector2(zi4.X, zi4.Y), Pus.Degree(zi4, zi3) * pi / 180 + pi / 2 + pi / 180, 1)), new Line(zii4, zi4), offset * 0.5, "αn=0°", dimensionStyle);
            else
                Pus.NeedleDim(dxf, new Line(new Vector2(zi4.X, zi4.Y), fun.Polar(new Vector2(zi4.X, zi4.Y), Pus.Degree(zi4, zi3) * pi / 180 + pi / 2, 1)), new Line(zii4, zi4), offset * 0.5, "αn=" + Math.Round(alphan * 180 / pi, 2) + "°", dimensionStyle);
            //图框
            if (Convert.ToDouble(data["isframe"]) == 1)
            {
                Vector2 c4c = new Vector2((b2.X + zb3.X) / 2, (b2.Y + mu1.Y) / 2);
                Dictionary<string, Vector2> positions = Frame.frameA3X(dxf, new Vector2(c4c.X - 420 / 2, c4c.Y + 297 / 2), new Dictionary<string, object>());
                fun.writetextofC(dxf, kscale + ":1", positions["比例"], 3.5, 0, 0.6, 3);
            }

            dxf.DrawingVariables.AcadVer = DxfVersion.AutoCad2007;
            dxf.Save(path);
        }
        public static void StyleF_InsertT(Dictionary<string, Object> data)
        {

            DxfDocument dxf = new DxfDocument();
            Layer contour = new Layer("contour") { Color = AciColor.Cyan };    //1,轮廓层
            Layer cutting = new Layer("cutting") { Color = AciColor.Red };    //切削层

            string path = Convert.ToString(data["path"]);
            //参数名称取自ISO 5610-2
            double a = 1.6;
            double b = 12;
            double l1 = 90;
            double l2 = 25;
            double f = 16;
            double l3 = 11;
            double h2 = 12;
            double h1 = 12;
            double s = 2.38;
            double insertAngle = pi / 3;
            double alphan = 7 * pi / 180;
            double cutagl = 90 * pi / 180;
            double lambdas = 0;
            double gamao = 0;
            double repsilon = 0;
            #region
            try
            {
                if (data["re"] != null)
                    repsilon = Convert.ToDouble(data["re"]);
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["lams"] != null)
                    lambdas = Convert.ToDouble(data["lams"]) * pi / 180;
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["gamo"] != null)
                    gamao = Convert.ToDouble(data["gamo"]) * pi / 180;
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["lfa"] != null)
                    a = Convert.ToDouble(data["lfa"]);
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["b"] != null)
                    b = Convert.ToDouble(data["b"]);
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["s"] != null)
                    s = Convert.ToDouble(data["s"]);
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["lf"] != null)
                    l1 = Convert.ToDouble(data["lf"]);
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["lh"] != null)
                    l2 = Convert.ToDouble(data["lh"]);
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["wf"] != null)
                    f = Convert.ToDouble(data["wf"]);
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["h"] != null)
                    h2 = Convert.ToDouble(data["h"]);
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["hf"] != null)
                    h1 = Convert.ToDouble(data["hf"]);
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["epsr"] != null)
                    insertAngle = Convert.ToDouble(data["epsr"]) * pi / 180;
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["kapr"] != null)
                    cutagl = Convert.ToDouble(data["kapr"]) * pi / 180;
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["an"] != null)
                    alphan = Convert.ToDouble(data["an"]) * pi / 180;
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["l"] != null)
                    l3 = Convert.ToDouble(data["l"]);
            }
            catch (KeyNotFoundException) { }
            #endregion
            //线性变换
            Vector2 zero = new Vector2(0, 0);
            double kscale = 1;
            if (l1 >= 120)
                kscale = 1;
            else
                kscale = 1.5;
            double lineWidth = 1;
            //k点位置恒定
            Vector3 k = new Vector3(0, 0, 0);
            Vector3 b2 = new Vector3(k.X + l1, k.Y + f, k.Z - h1);
            Vector3 b1 = new Vector3(b2.X, b2.Y - b, b2.Z);
            Vector3 b6 = new Vector3(k.X + l2, b1.Y, b1.Z);

            //刀杆顶面
            Vector3 u1 = new Vector3(b1.X, b1.Y, b1.Z + h2);
            Vector3 u2 = new Vector3(b2.X, b2.Y, b2.Z + h2);
            Vector3 u3 = new Vector3(b6.X, b2.Y, b2.Z + h2);
            Vector3 u4 = new Vector3(b6.X, b6.Y, b6.Z + h2);

            //前角与刃倾角都为0时刀尖点与k的关系
            Vector2 cen = fun.Polar(new Vector2(k.X, k.Y), pi / 4, repsilon / Math.Sin(pi / 4));
            Vector2 twoi3 = fun.Polar(cen, 2 * pi - cutagl - insertAngle / 2, repsilon / Math.Sin(insertAngle / 2));
            Vector2[] twois = Pus.TrianglePoints(twoi3, l3, false, cutagl);
            Vector2 twoi1 = twois[1];
            Vector2 twoi2 = twois[2];
            double theoffset = Math.Tan(alphan) * s;
            Vector2[] twoiis = Pus.OffsetPoints(theoffset, twois);
            Vector2 twoii3 = twoiis[0];
            Vector2 twoii1 = twoiis[1];
            Vector2 twoii2 = twoiis[2];

            Vector3 b5 = new Vector3(twoii3.X, twoii3.Y, b1.Z);
            Vector3 b4 = new Vector3(twoi2.X, twoi2.Y + 2, b1.Z);
            Vector3 b3 = new Vector3(b4.X + 3, b2.Y, b1.Z);

            //刀头面
            Vector3 i3 = new Vector3(twoi3.X, twoi3.Y, k.Z);
            Vector3 i2 = new Vector3(twoi2.X, twoi2.Y, k.Z);
            Vector3 i1 = new Vector3(twoi1.X, twoi1.Y, k.Z);
            Vector3 x1 = Pus.KPoint(i3, i1, 0.3);
            Vector3 dt1 = u4;
            Vector3 dt2 = u3;
            Vector3 dt3 = new Vector3(b3.X, b3.Y, b3.Z + h2);
            Vector3 dt4 = new Vector3(b4.X, b4.Y, b4.Z + h2);

            Vector3 ii3 = new Vector3(twoii3.X, twoii3.Y, k.Z - s);
            Vector3 ii1 = new Vector3(twoii1.X, twoii1.Y, k.Z - s);
            Vector3 ii2 = new Vector3(twoii2.X, twoii2.Y, k.Z - s);
            Vector3 xx1 = Pus.KPoint(ii3, ii1, 0.3);

            Vector3 x2 = Pus.KPoint(i3, dt1, 0.1);
            Vector3 xx2 = Pus.Inters(new Face3d(ii3, ii1, ii2), new Line(x2, x2 + (xx1 - x1)));

            i3 = Pus.LinearTrans(kscale, i3);
            i2 = Pus.LinearTrans(kscale, i2);
            i1 = Pus.LinearTrans(kscale, i1);
            dt1 = Pus.LinearTrans(kscale, dt1);
            dt2 = Pus.LinearTrans(kscale, dt2);
            dt3 = Pus.LinearTrans(kscale, dt3);
            dt4 = Pus.LinearTrans(kscale, dt4);
            ii3 = Pus.LinearTrans(kscale, ii3);
            ii2 = Pus.LinearTrans(kscale, ii2);
            ii1 = Pus.LinearTrans(kscale, ii1);

            b1 = Pus.LinearTrans(kscale, b1);
            b2 = Pus.LinearTrans(kscale, b2);
            b3 = Pus.LinearTrans(kscale, b3);
            b4 = Pus.LinearTrans(kscale, b4);
            b5 = Pus.LinearTrans(kscale, b5);
            b6 = Pus.LinearTrans(kscale, b6);

            u1 = Pus.LinearTrans(kscale, u1);
            u2 = Pus.LinearTrans(kscale, u2);
            u3 = Pus.LinearTrans(kscale, u3);
            u4 = Pus.LinearTrans(kscale, u4);

            //重新计算x点
            x1 = Pus.LinearTrans(kscale, x1);
            xx1 = Pus.LinearTrans(kscale, xx1);
            x2 = Pus.LinearTrans(kscale, x2);
            xx2 = Pus.LinearTrans(kscale, xx2);

            //主视图
            LwPolyline mshank = Pus.AddPointsToLwPolyLine(u1, u2, u3, u4);
            mshank.IsClosed = true;
            fun.PolyFill(dxf, mshank, lineWidth, contour);

            LwPolyline minsert = Pus.AddPointsToLwPolyLine(i3, i1, i2);
            minsert.IsClosed = true;
            Pus.AglToArc(minsert, repsilon);
            fun.PolyFill(dxf, minsert, lineWidth, cutting);

            LwPolyline mhead = Pus.AddPointsToLwPolyLine(x1, x2, dt1, dt2, dt3, dt4, i2);
            Pus.AddPointsToLwPolyLine(mhead, minsert.Vertexes[4].Position);
            fun.PolyFill(dxf, mhead, lineWidth, contour);
            fun.drawBLine(dxf, new Vector2[] { minsert.Vertexes[5].Position, new Vector2(i2.X, i2.Y) }, lineWidth, contour);
            fun.drawBLine(dxf, new Vector2[] { minsert.Vertexes[1].Position, new Vector2(xx2.X, xx2.Y) }, lineWidth, contour);
            //主视图标注
            DimensionStyle dimensionStyle = new DimensionStyle("mystyle");
            dimensionStyle.ArrowSize = 0.2;
            dimensionStyle.DimArrow1 = DimensionArrowhead.Closedfilled;
            dimensionStyle.DimArrow2 = DimensionArrowhead.Closedfilled;
            dimensionStyle.TextHeight = kscale;
            dimensionStyle.TextOffset = kscale / 2;
            double offset = 7 * kscale;
            LinearDimension dim_f = new LinearDimension(new Line(new Vector2(k.X, k.Y), new Vector2(b3.X, b3.Y)), offset, Pus.Degree(b1, b2), dimensionStyle);
            fun.dxflinedim(dxf, dim_f, f);
            LinearDimension dim_l1 = new LinearDimension(new Line(new Vector2(k.X, k.Y), new Vector2(b1.X, b1.Y)), offset, Pus.Degree(new Vector2(b1.X, b1.Y), new Vector2(b6.X, b6.Y)), dimensionStyle);
            fun.dxflinedim(dxf, dim_l1, l1);
            LinearDimension dim_l2 = new LinearDimension(new Line(new Vector2(k.X, k.Y), new Vector2(u4.X, u4.Y)), offset * 0.7, Pus.Degree(new Vector2(u1.X, u1.Y), new Vector2(u4.X, u4.Y)), dimensionStyle);
            fun.dxflinedim(dxf, dim_l2, l2);
            LinearDimension dim_l3 = new LinearDimension(new Line(new Vector2(i1.X, i1.Y), new Vector2(i2.X, i2.Y)), offset * 0.5, Pus.Degree(new Vector2(i2.X, i2.Y), new Vector2(i1.X, i1.Y)), dimensionStyle);
            fun.dxflinedim(dxf, dim_l3, Math.Round(l3, 2));
            LinearDimension dim_b = new LinearDimension(new Line(new Vector2(u1.X, u1.Y), new Vector2(u2.X, u2.Y)), offset, Pus.Degree(new Vector2(u2.X, u2.Y), new Vector2(u1.X, u1.Y)), dimensionStyle);
            fun.dxflinedim(dxf, dim_b, b);
            //Angular2LineDimension dim_insertAgl = new Angular2LineDimension(new Line(i3, i2), new Line(i3, i1), offset * 0.5, dimensionStyle);
            //dim_insertAgl.UserText = Math.Round(insertAngle * 180 / pi, 2) + "°";
            //dxf.AddEntity(dim_insertAgl);
            Angular2LineDimension dim_cutagl = new Angular2LineDimension(new Line(new Vector2(i3.X, i3.Y), new Vector2(i2.X, i2.Y)), new Line(new Vector2(i3.X, i3.Y), fun.Polar(new Vector2(i3.X, i3.Y), pi, 1)), offset * 0.4, dimensionStyle);
            dim_cutagl.UserText = Math.Round(cutagl * 180 / pi, 2) + "°";
            dxf.AddEntity(dim_cutagl);
            RadialDimension dim_repsilon = new RadialDimension(Pus.GetArcFromPline(minsert, 1), Pus.Degree(i2, i3) - 45, offset * 0.5, dimensionStyle);
            dim_repsilon.UserText = "rε=" + repsilon;
            dxf.AddEntity(dim_repsilon);
            //放倒(所有点)尚未平移到下方，因为只能绕着原点k所在轴旋转
            Vector3 rotate = new Vector3(-1, 0, 0);
            double rotateAgl = pi / 2;
            i3 = Pus.Rodrigue(rotate, 1, rotateAgl, i3);
            i2 = Pus.Rodrigue(rotate, 1, rotateAgl, i2);
            i1 = Pus.Rodrigue(rotate, 1, rotateAgl, i1);
            dt1 = Pus.Rodrigue(rotate, 1, rotateAgl, dt1);
            dt2 = Pus.Rodrigue(rotate, 1, rotateAgl, dt2);
            dt3 = Pus.Rodrigue(rotate, 1, rotateAgl, dt3);
            dt4 = Pus.Rodrigue(rotate, 1, rotateAgl, dt4);
            ii3 = Pus.Rodrigue(rotate, 1, rotateAgl, ii3);
            ii2 = Pus.Rodrigue(rotate, 1, rotateAgl, ii2);
            ii1 = Pus.Rodrigue(rotate, 1, rotateAgl, ii1);

            b1 = Pus.Rodrigue(rotate, 1, rotateAgl, b1);
            b2 = Pus.Rodrigue(rotate, 1, rotateAgl, b2);
            b3 = Pus.Rodrigue(rotate, 1, rotateAgl, b3);
            b4 = Pus.Rodrigue(rotate, 1, rotateAgl, b4);
            b5 = Pus.Rodrigue(rotate, 1, rotateAgl, b5);
            b6 = Pus.Rodrigue(rotate, 1, rotateAgl, b6);

            u1 = Pus.Rodrigue(rotate, 1, rotateAgl, u1);
            u2 = Pus.Rodrigue(rotate, 1, rotateAgl, u2);
            u3 = Pus.Rodrigue(rotate, 1, rotateAgl, u3);
            u4 = Pus.Rodrigue(rotate, 1, rotateAgl, u4);

            //重新计算x点
            x1 = Pus.KPoint(i3, i1, 0.3);
            xx1 = Pus.KPoint(ii3, ii1, 0.3);
            x2 = Pus.Rodrigue(rotate, 1, rotateAgl, x2);
            xx2 = Pus.Rodrigue(rotate, 1, rotateAgl, xx2);

            //创建lambds
            rotate = new Vector3(Math.Cos(pi - cutagl + pi / 2), Math.Sin(pi - cutagl + pi / 2), k.Z);
            rotateAgl = -lambdas;
            i3 = Pus.Rodrigue(rotate, 1, rotateAgl, i3);
            i2 = Pus.Rodrigue(rotate, 1, rotateAgl, i2);
            i1 = Pus.Rodrigue(rotate, 1, rotateAgl, i1);
            ii3 = Pus.Rodrigue(rotate, 1, rotateAgl, ii3);
            ii2 = Pus.Rodrigue(rotate, 1, rotateAgl, ii2);
            ii1 = Pus.Rodrigue(rotate, 1, rotateAgl, ii1);
            dt1 = Pus.Rodrigue(rotate, 1, rotateAgl, dt1);
            dt2 = Pus.Rodrigue(rotate, 1, rotateAgl, dt2);
            dt3 = Pus.Rodrigue(rotate, 1, rotateAgl, dt3);
            dt4 = Pus.Rodrigue(rotate, 1, rotateAgl, dt4);

            //重新计算x点
            x1 = Pus.KPoint(i3, i1, 0.3);
            xx1 = Pus.KPoint(ii3, ii1, 0.3);
            x2 = Pus.Rodrigue(rotate, 1, rotateAgl, x2);
            xx2 = Pus.Rodrigue(rotate, 1, rotateAgl, xx2);

            //创建gamo
            double disi2_i3 = Vector3.Distance(i2, i3);
            rotate = (i2 - i3) / disi2_i3;
            rotateAgl = -gamao;
            i3 = Pus.Rodrigue(rotate, 1, rotateAgl, i3);
            i2 = Pus.Rodrigue(rotate, 1, rotateAgl, i2);
            i1 = Pus.Rodrigue(rotate, 1, rotateAgl, i1);
            ii3 = Pus.Rodrigue(rotate, 1, rotateAgl, ii3);
            ii2 = Pus.Rodrigue(rotate, 1, rotateAgl, ii2);
            ii1 = Pus.Rodrigue(rotate, 1, rotateAgl, ii1);
            dt1 = Pus.Rodrigue(rotate, 1, rotateAgl, dt1);
            dt2 = Pus.Rodrigue(rotate, 1, rotateAgl, dt2);
            dt3 = Pus.Rodrigue(rotate, 1, rotateAgl, dt3);
            dt4 = Pus.Rodrigue(rotate, 1, rotateAgl, dt4);

            //重新计算x点
            x1 = Pus.KPoint(i3, i1, 0.3);
            xx1 = Pus.KPoint(ii3, ii1, 0.3);
            x2 = Pus.Rodrigue(rotate, 1, rotateAgl, x2);
            xx2 = Pus.Rodrigue(rotate, 1, rotateAgl, xx2);
            //重新计算刀头的点
            Face3d face4dt = new Face3d(dt2, dt3, dt4);
            Vector3 v4dt = u2 - b2;
            Vector3 u3p = new Vector3(u3.X - 1, u3.Y, u3.Z);
            dt2 = Pus.Inters(face4dt, new Line(u3p, u3p + v4dt));
            dt3 = Pus.Inters(face4dt, new Line(b3, b3 + v4dt));
            dt4 = Pus.Inters(face4dt, new Line(b4, b4 + v4dt));

            Face3d face4buttom = new Face3d(b1, b2, b3);
            b5 = Pus.Inters(face4buttom, new Line(i3, ii3));

            //平移所有点到下方
            Vector3 voff = new Vector3(0, -20 * kscale, 0);
            Vector3 mk = Pus.OffsetXY(voff, k);
            Vector3 mi3 = Pus.OffsetXY(voff, i3);
            Vector3 mi2 = Pus.OffsetXY(voff, i2);
            Vector3 mi1 = Pus.OffsetXY(voff, i1);
            Vector3 mdt1 = Pus.OffsetXY(voff, dt1);
            Vector3 mdt2 = Pus.OffsetXY(voff, dt2);
            Vector3 mdt3 = Pus.OffsetXY(voff, dt3);
            Vector3 mdt4 = Pus.OffsetXY(voff, dt4);
            Vector3 mii3 = Pus.OffsetXY(voff, ii3);
            Vector3 mii2 = Pus.OffsetXY(voff, ii2);
            Vector3 mii1 = Pus.OffsetXY(voff, ii1);

            Vector3 mb1 = Pus.OffsetXY(voff, b1);
            Vector3 mb2 = Pus.OffsetXY(voff, b2);
            Vector3 mb3 = Pus.OffsetXY(voff, b3);
            Vector3 mb4 = Pus.OffsetXY(voff, b4);
            Vector3 mb5 = Pus.OffsetXY(voff, b5);
            Vector3 mb6 = Pus.OffsetXY(voff, b6);

            Vector3 mu1 = Pus.OffsetXY(voff, u1);
            Vector3 mu2 = Pus.OffsetXY(voff, u2);
            Vector3 mu3 = Pus.OffsetXY(voff, u3);
            Vector3 mu4 = Pus.OffsetXY(voff, u4);

            Vector3 mx1 = Pus.OffsetXY(voff, x1);
            Vector3 mx2 = Pus.OffsetXY(voff, x2);
            Vector3 mxx1 = Pus.OffsetXY(voff, xx1);
            Vector3 mxx2 = Pus.OffsetXY(voff, xx2);

            LwPolyline lshank = Pus.AddPointsToLwPolyLine(mb1, mu1, mu4, mb6);
            lshank.IsClosed = true;
            fun.PolyFill(dxf, lshank, lineWidth, contour);
            LwPolyline lshank_dt = Pus.AddPointsToLwPolyLine(mdt1, mu4);
            fun.PolyFill(dxf, lshank_dt, lineWidth, contour);

            LwPolyline linsertu = Pus.AddPointsToLwPolyLine(mi3, mi1, mi2);
            linsertu.IsClosed = true;
            fun.PolyFill(dxf, linsertu, lineWidth, cutting);
            fun.drawBLine(dxf, new Vector2[] { new Vector2(mii3.X, mii3.Y), new Vector2(mi3.X, mi3.Y) }, lineWidth, cutting);

            LwPolyline lhead = Pus.AddPointsToLwPolyLine(mb6, mdt1, mx2, mxx2, mii3, mb5);
            lhead.IsClosed = true;
            fun.PolyFill(dxf, lhead, lineWidth, contour);
            LwPolyline lheadu = Pus.AddPointsToLwPolyLine(mx1, mx2, mdt1, mdt2, mdt3, mdt4, mi2);
            fun.PolyFill(dxf, lheadu, lineWidth, contour);
            fun.drawBLine(dxf, new Vector2[] { new Vector2(mx1.X, mx1.Y), new Vector2(mxx1.X, mxx1.Y) }, lineWidth, contour);
            fun.drawBLine(dxf, new Vector2[] { new Vector2(mxx1.X, mxx1.Y), new Vector2(mxx2.X, mxx2.Y) }, lineWidth, contour);
            //m视图标注
            LinearDimension dim_h1 = new LinearDimension(new Line(new Vector2(mk.X, mk.Y), new Vector2(mb5.X, mb5.Y)), offset * 0.5, Pus.Degree(b1, u1), dimensionStyle);
            fun.dxflinedim(dxf, dim_h1, h1);
            LinearDimension dim_h2 = new LinearDimension(new Line(new Vector2(mu1.X, mu1.Y), new Vector2(mb1.X, mb1.Y)), offset, Pus.Degree(u1, b1), dimensionStyle);
            fun.dxflinedim(dxf, dim_h2, h2);
            //gammao
            if (gamao == 0)
                Pus.NeedleDim(dxf, new Line(new Vector2(mi3.X, mi3.Y), fun.Polar(new Vector2(mi3.X, mi3.Y), pi + pi / 180, 1)), new Line(new Vector2(mi3.X, mi3.Y), fun.Polar(new Vector2(mi3.X, mi3.Y), pi, 1)), offset, "γo=0°", dimensionStyle);
            else
                Pus.NeedleDim(dxf, new Line(mi1, mi3), new Line(new Vector2(mi3.X, mi3.Y), fun.Polar(new Vector2(mi3.X, mi3.Y), pi, 1)), offset, "γo=" + Math.Round(gamao * 180 / pi, 2) + "°", dimensionStyle);
            //左视图
            //所有点移动到原点
            //立正
            rotate = new Vector3(1, 0, 0);
            rotateAgl = pi / 2;
            Vector3 zi3 = Pus.Rodrigue(rotate, 1, rotateAgl, i3);
            Vector3 zi2 = Pus.Rodrigue(rotate, 1, rotateAgl, i2);
            Vector3 zi1 = Pus.Rodrigue(rotate, 1, rotateAgl, i1);
            Vector3 zdt1 = Pus.Rodrigue(rotate, 1, rotateAgl, dt1);
            Vector3 zdt2 = Pus.Rodrigue(rotate, 1, rotateAgl, dt2);
            Vector3 zdt3 = Pus.Rodrigue(rotate, 1, rotateAgl, dt3);
            Vector3 zdt4 = Pus.Rodrigue(rotate, 1, rotateAgl, dt4);
            Vector3 zii3 = Pus.Rodrigue(rotate, 1, rotateAgl, ii3);
            Vector3 zii2 = Pus.Rodrigue(rotate, 1, rotateAgl, ii2);
            Vector3 zii1 = Pus.Rodrigue(rotate, 1, rotateAgl, ii1);

            Vector3 zb1 = Pus.Rodrigue(rotate, 1, rotateAgl, b1);
            Vector3 zb2 = Pus.Rodrigue(rotate, 1, rotateAgl, b2);
            Vector3 zb3 = Pus.Rodrigue(rotate, 1, rotateAgl, b3);
            Vector3 zb4 = Pus.Rodrigue(rotate, 1, rotateAgl, b4);
            Vector3 zb5 = Pus.Rodrigue(rotate, 1, rotateAgl, b5);
            Vector3 zb6 = Pus.Rodrigue(rotate, 1, rotateAgl, b6);

            Vector3 zu1 = Pus.Rodrigue(rotate, 1, rotateAgl, u1);
            Vector3 zu2 = Pus.Rodrigue(rotate, 1, rotateAgl, u2);
            Vector3 zu3 = Pus.Rodrigue(rotate, 1, rotateAgl, u3);
            Vector3 zu4 = Pus.Rodrigue(rotate, 1, rotateAgl, u4);

            Vector3 zx1 = Pus.Rodrigue(rotate, 1, rotateAgl, x1);
            Vector3 zx2 = Pus.Rodrigue(rotate, 1, rotateAgl, x2);
            Vector3 zxx1 = Pus.Rodrigue(rotate, 1, rotateAgl, xx1);
            Vector3 zxx2 = Pus.Rodrigue(rotate, 1, rotateAgl, xx2);

            //绕y转，露出左面
            rotate = new Vector3(0, 1, 0);
            rotateAgl = pi / 2;
            zi3 = Pus.Rodrigue(rotate, 1, rotateAgl, zi3);
            zi2 = Pus.Rodrigue(rotate, 1, rotateAgl, zi2);
            zi1 = Pus.Rodrigue(rotate, 1, rotateAgl, zi1);
            zdt1 = Pus.Rodrigue(rotate, 1, rotateAgl, zdt1);
            zdt2 = Pus.Rodrigue(rotate, 1, rotateAgl, zdt2);
            zdt3 = Pus.Rodrigue(rotate, 1, rotateAgl, zdt3);
            zdt4 = Pus.Rodrigue(rotate, 1, rotateAgl, zdt4);
            zii3 = Pus.Rodrigue(rotate, 1, rotateAgl, zii3);
            zii2 = Pus.Rodrigue(rotate, 1, rotateAgl, zii2);
            zii1 = Pus.Rodrigue(rotate, 1, rotateAgl, zii1);

            zb1 = Pus.Rodrigue(rotate, 1, rotateAgl, zb1);
            zb2 = Pus.Rodrigue(rotate, 1, rotateAgl, zb2);
            zb3 = Pus.Rodrigue(rotate, 1, rotateAgl, zb3);
            zb4 = Pus.Rodrigue(rotate, 1, rotateAgl, zb4);
            zb5 = Pus.Rodrigue(rotate, 1, rotateAgl, zb5);
            zb6 = Pus.Rodrigue(rotate, 1, rotateAgl, zb6);

            zu1 = Pus.Rodrigue(rotate, 1, rotateAgl, zu1);
            zu2 = Pus.Rodrigue(rotate, 1, rotateAgl, zu2);
            zu3 = Pus.Rodrigue(rotate, 1, rotateAgl, zu3);
            zu4 = Pus.Rodrigue(rotate, 1, rotateAgl, zu4);

            zx1 = Pus.Rodrigue(rotate, 1, rotateAgl, zx1);
            zx2 = Pus.Rodrigue(rotate, 1, rotateAgl, zx2);
            zxx1 = Pus.Rodrigue(rotate, 1, rotateAgl, zxx1);
            zxx2 = Pus.Rodrigue(rotate, 1, rotateAgl, zxx2);

            //平移
            voff = new Vector3(-20 * kscale, 0, 0);
            zi3 = Pus.OffsetXY(voff, zi3);
            zi2 = Pus.OffsetXY(voff, zi2);
            zi1 = Pus.OffsetXY(voff, zi1);
            zdt1 = Pus.OffsetXY(voff, zdt1);
            zdt2 = Pus.OffsetXY(voff, zdt2);
            zdt3 = Pus.OffsetXY(voff, zdt3);
            zdt4 = Pus.OffsetXY(voff, zdt4);
            zii3 = Pus.OffsetXY(voff, zii3);
            zii2 = Pus.OffsetXY(voff, zii2);
            zii1 = Pus.OffsetXY(voff, zii1);

            zb1 = Pus.OffsetXY(voff, zb1);
            zb2 = Pus.OffsetXY(voff, zb2);
            zb3 = Pus.OffsetXY(voff, zb3);
            zb4 = Pus.OffsetXY(voff, zb4);
            zb5 = Pus.OffsetXY(voff, zb5);
            zb6 = Pus.OffsetXY(voff, zb6);

            zu1 = Pus.OffsetXY(voff, zu1);
            zu2 = Pus.OffsetXY(voff, zu2);
            zu3 = Pus.OffsetXY(voff, zu3);
            zu4 = Pus.OffsetXY(voff, zu4);

            zx1 = Pus.OffsetXY(voff, zx1);
            zx2 = Pus.OffsetXY(voff, zx2);
            zxx1 = Pus.OffsetXY(voff, zxx1);
            zxx2 = Pus.OffsetXY(voff, zxx2);

            //左视图绘制
            LwPolyline zshank = Pus.AddPointsToLwPolyLine(zii3, zb5, zb4, zb3, zdt3, zdt4, zi2);
            fun.PolyFill(dxf, zshank, lineWidth, contour);
            LwPolyline zshank1 = Pus.AddPointsToLwPolyLine(zdt3, zdt2, zdt1, zx2, zx1);
            fun.PolyFill(dxf, zshank1, lineWidth, contour);
            LwPolyline zshank2 = Pus.AddPointsToLwPolyLine(zb4, zdt4);
            fun.PolyFill(dxf, zshank2, lineWidth, contour);

            LwPolyline zinsert = Pus.AddPointsToLwPolyLine(zi3, zi1, zi2);
            zinsert.IsClosed = true;
            fun.PolyFill(dxf, zinsert, lineWidth, cutting);
            LwPolyline zlen1 = Pus.AddPointsToLwPolyLine(zi2, zii2, zii3, zi3);
            fun.PolyFill(dxf, zlen1, lineWidth, cutting);
            //左视图标注
            //刃倾角
            if (lambdas == 0)
                Pus.NeedleDim(dxf, new Line(new Vector2(zi3.X, zi3.Y), fun.Polar(new Vector2(zi3.X, zi3.Y), pi / 2 + pi / 180, 1)), new Line(zi2, zi3), offset, "λs=0°", dimensionStyle);
            else
                Pus.NeedleDim(dxf, new Line(zi2, zi3), new Line(new Vector2(zi3.X, zi3.Y), fun.Polar(new Vector2(zi3.X, zi3.Y), pi / 2, 1)), offset, "λs=" + Math.Round(lambdas * 180 / pi, 2) + "°", dimensionStyle);
            LinearDimension dim_s = new LinearDimension(new Line(zi3, zii3), offset * 0.5, Pus.Degree(zi3, zi2) + 90, dimensionStyle);
            fun.dxflinedim(dxf, dim_s, s);
            //后角
            if (alphan == 0)
                Pus.NeedleDim(dxf, new Line(new Vector2(zi3.X, zi3.Y), fun.Polar(new Vector2(zi3.X, zi3.Y), Pus.Degree(zi3, zi2) * pi / 180 + pi / 2 + pi / 180, 1)), new Line(zii3, zi3), offset * 0.5, "αn=0°", dimensionStyle);
            else
                Pus.NeedleDim(dxf, new Line(new Vector2(zi3.X, zi3.Y), fun.Polar(new Vector2(zi3.X, zi3.Y), Pus.Degree(zi3, zi2) * pi / 180 + pi / 2, 1)), new Line(zii3, zi3), offset * 0.5, "αn=" + Math.Round(alphan * 180 / pi, 2) + "°", dimensionStyle);
            //图框
            if (Convert.ToDouble(data["isframe"]) == 1)
            {
                Vector2 c4c = new Vector2((b2.X + zb3.X) / 2, (b2.Y + mu1.Y) / 2);
                Dictionary<string, Vector2> positions = Frame.frameA3X(dxf, new Vector2(c4c.X - 420 / 2, c4c.Y + 297 / 2), new Dictionary<string, object>());
                fun.writetextofC(dxf, kscale + ":1", positions["比例"], 3.5, 0, 0.6, 3);
            }

            dxf.DrawingVariables.AcadVer = DxfVersion.AutoCad2007;
            dxf.Save(path);
        }
        //H型刀头 横大
        public static void StyleH_InsertD(Dictionary<string, Object> data)
        {

            DxfDocument dxf = new DxfDocument();
            Layer contour = new Layer("contour") { Color = AciColor.Cyan };    //1,轮廓层
            Layer cutting = new Layer("cutting") { Color = AciColor.Red };    //切削层

            string path = Convert.ToString(data["path"]);
            //参数名称取自ISO 5610-2
            double b = 10;
            double l1 = 70;
            double l2 = 25;
            double f = 12;
            double l3 = 7.75;
            double h2 = 10;
            double h1 = 10;
            double s = 2.38;
            double insertAngle = 55 * pi / 180;
            double alphan = 7 * pi / 180;
            double cutagl = 107.5 * pi / 180;
            double lambdas = 0;
            double gamao = 0;
            double repsilon = 0;
            #region
            try
            {
                if (data["re"] != null)
                    repsilon = Convert.ToDouble(data["re"]);
                if (repsilon <= 0)
                    repsilon = 0.01;
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["lams"] != null)
                    lambdas = Math.Abs(Convert.ToDouble(data["lams"]) * pi / 180);
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["gamo"] != null)
                    gamao = Math.Abs(Convert.ToDouble(data["gamo"]) * pi / 180);
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["b"] != null)
                    b = Convert.ToDouble(data["b"]);
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["s"] != null)
                    s = Convert.ToDouble(data["s"]);
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["lf"] != null)
                    l1 = Convert.ToDouble(data["lf"]);
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["lh"] != null)
                    l2 = Convert.ToDouble(data["lh"]);
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["wf"] != null)
                    f = Convert.ToDouble(data["wf"]);
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["h"] != null)
                    h2 = Convert.ToDouble(data["h"]);
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["hf"] != null)
                    h1 = Convert.ToDouble(data["hf"]);
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["epsr"] != null)
                    insertAngle = Convert.ToDouble(data["epsr"]) * pi / 180;
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["kapr"] != null)
                    cutagl = Convert.ToDouble(data["kapr"]) * pi / 180;
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["an"] != null)
                    alphan = Convert.ToDouble(data["an"]) * pi / 180;
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["l"] != null)
                    l3 = Convert.ToDouble(data["l"]);
            }
            catch (KeyNotFoundException) { }
            #endregion
            double kscale = 1;
            if (l1 >= 120)
                kscale = 1;
            else
                kscale = 1.5;
            double lineWidth = 1;
            //k点位置恒定
            Vector3 k = new Vector3(0, 0, 0);
            Vector3 b2 = new Vector3(k.X + l1, k.Y + f, k.Z - h1);
            Vector3 b1 = new Vector3(b2.X, b2.Y - b, b2.Z);
            Vector3 b6 = new Vector3(k.X + l2, b1.Y, b1.Z);

            //刀杆顶面
            Vector3 u1 = new Vector3(b1.X, b1.Y, b1.Z + h2);
            Vector3 u2 = new Vector3(b2.X, b2.Y, b2.Z + h2);
            Vector3 u3 = new Vector3(b6.X, b2.Y, b2.Z + h2);
            double guai = kscale;
            Vector3 u3p = new Vector3(u3.X - guai, u3.Y, u3.Z);
            Vector3 u4 = new Vector3(b6.X, b6.Y, b6.Z + h2);
            Vector3 u4p = new Vector3(u4.X - guai, u4.Y, u4.Z);

            //Kp=fun.polar(K,0,r/tan((pi-kapr)/2)-r)
            //i4=fun.polar(Kp,kapr-pi,r/tan(epsr/2)-r/tan((pi-kapr)/2))
            Vector2 kp = fun.Polar(Vector2.Zero, 0, repsilon / Math.Tan((pi - cutagl) / 2) - repsilon);
            Vector2 twoi4 = fun.Polar(kp, cutagl - pi, repsilon / Math.Tan(insertAngle / 2) - repsilon / Math.Tan((pi - cutagl) / 2));
            Vector2[] twois = Pus.DiamondPoints(twoi4, l3, insertAngle, true, cutagl);
            Vector2 twoi1 = twois[1];
            Vector2 twoi2 = twois[2];
            Vector2 twoi3 = twois[3];
            double theoffset = Math.Tan(alphan) * s;
            Vector2[] twoiis = Pus.OffsetPoints(theoffset, twois);
            Vector2 twoii4 = twoiis[0];
            Vector2 twoii3 = twoiis[3];
            Vector2 twoii1 = twoiis[1];
            Vector2 twoii2 = twoiis[2];

            //刀头面
            Vector3 i4 = new Vector3(twoi4.X, twoi4.Y, k.Z);
            Vector3 i3 = new Vector3(twoi3.X, twoi3.Y, k.Z);
            Vector3 i2 = new Vector3(twoi2.X, twoi2.Y, k.Z);
            Vector3 i1 = new Vector3(twoi1.X, twoi1.Y, k.Z);
            Vector2 cnm = Pus.IntersOnP(i1, new Vector3(i1.X + 1, i1.Y, i1.Z), u3p, u4p);
            Vector3 dt1 = new Vector3(cnm.X, cnm.Y, u4.Z);
            Vector3 dt2 = u3p;
            Vector2 xx = Pus.IntersOnP(i3, i4, u2, u3);
            Vector3 dt4 = Pus.KPoint(i3, new Vector3(xx.X, xx.Y, u3.Z), 0.7);
            Vector3 dt3 = Pus.KPoint(u3, new Vector3(xx.X, xx.Y, u3.Z), 0.85);

            Vector3 bdt1 = new Vector3(dt1.X, dt1.Y, b1.Z);
            Vector3 b5 = new Vector3(twoii4.X, twoii4.Y, b1.Z);
            Vector3 b4 = new Vector3(dt4.X, dt4.Y, b1.Z);
            Vector3 b3 = new Vector3(dt3.X, dt3.Y, b1.Z);

            Vector3 ii4 = new Vector3(twoii4.X, twoii4.Y, k.Z - s);
            Vector3 ii3 = new Vector3(twoii3.X, twoii3.Y, k.Z - s);
            Vector3 ii1 = new Vector3(twoii1.X, twoii1.Y, k.Z - s);
            Vector3 ii2 = new Vector3(twoii2.X, twoii2.Y, k.Z - s);

            i4 = Pus.LinearTrans(kscale, i4);
            i3 = Pus.LinearTrans(kscale, i3);
            i2 = Pus.LinearTrans(kscale, i2);
            i1 = Pus.LinearTrans(kscale, i1);
            dt1 = Pus.LinearTrans(kscale, dt1);
            dt2 = Pus.LinearTrans(kscale, dt2);
            dt3 = Pus.LinearTrans(kscale, dt3);
            dt4 = Pus.LinearTrans(kscale, dt4);

            ii4 = Pus.LinearTrans(kscale, ii4);
            ii3 = Pus.LinearTrans(kscale, ii3);
            ii2 = Pus.LinearTrans(kscale, ii2);
            ii1 = Pus.LinearTrans(kscale, ii1);

            b1 = Pus.LinearTrans(kscale, b1);
            b2 = Pus.LinearTrans(kscale, b2);
            b3 = Pus.LinearTrans(kscale, b3);
            b4 = Pus.LinearTrans(kscale, b4);
            b5 = Pus.LinearTrans(kscale, b5);
            b6 = Pus.LinearTrans(kscale, b6);
            bdt1 = Pus.LinearTrans(kscale, bdt1);

            u1 = Pus.LinearTrans(kscale, u1);
            u2 = Pus.LinearTrans(kscale, u2);
            u3 = Pus.LinearTrans(kscale, u3);
            u3p = Pus.LinearTrans(kscale, u3p);
            u4 = Pus.LinearTrans(kscale, u4);


            //主视图
            LwPolyline mshank = Pus.AddPointsToLwPolyLine(u1, u2, u3, u4);
            mshank.IsClosed = true;
            fun.PolyFill(dxf, mshank, lineWidth, contour);

            LwPolyline minsert = Pus.AddPointsToLwPolyLine(i4, i1, i2, i3);
            minsert.IsClosed = true;
            Pus.AglToArc(minsert, repsilon);

            LwPolyline mhead = Pus.AddPointsToLwPolyLine(i3, i2, i1, dt1, dt2, dt3, dt4, i3);
            mhead.IsClosed = true;
            fun.PolyFill(dxf, mhead, lineWidth, contour);
            LwPolyline mheadc1 = Pus.AddPointsToLwPolyLine(dt1, u4);
            fun.PolyFill(dxf, mheadc1, lineWidth, contour);
            LwPolyline mheadc2 = Pus.AddPointsToLwPolyLine(dt2, u3);
            fun.PolyFill(dxf, mheadc2, lineWidth, contour);

            fun.PolyFill(dxf, minsert, lineWidth, cutting);
            //m视图标注
            DimensionStyle dimensionStyle = new DimensionStyle("mystyle");
            dimensionStyle.ArrowSize = kscale * 1.2;
            dimensionStyle.DimArrow1 = DimensionArrowhead.Closedfilled;
            dimensionStyle.DimArrow2 = DimensionArrowhead.Closedfilled;
            dimensionStyle.TextHeight = kscale;
            dimensionStyle.TextOffset = kscale / 2;
            double offset = 7 * kscale;
            LinearDimension dim_f = new LinearDimension(new Line(new Vector2(k.X, k.Y), new Vector2(b3.X, b3.Y)), offset * 1.5, Pus.Degree(b1, b2), dimensionStyle);
            fun.dxflinedim(dxf, dim_f, f);
            LinearDimension dim_l1 = new LinearDimension(new Line(new Vector2(k.X, k.Y), new Vector2(b1.X, b1.Y)), offset * 1.5, Pus.Degree(new Vector2(b1.X, b1.Y), new Vector2(b6.X, b6.Y)), dimensionStyle);
            fun.dxflinedim(dxf, dim_l1, l1);
            LinearDimension dim_l2 = new LinearDimension(new Line(new Vector2(k.X, k.Y), new Vector2(u4.X, u4.Y)), offset, Pus.Degree(new Vector2(u1.X, u1.Y), new Vector2(u4.X, u4.Y)), dimensionStyle);
            fun.dxflinedim(dxf, dim_l2, l2);
            //LinearDimension dim_l3 = new LinearDimension(new Line(i2, i3), offset, Pus.Degree(new Vector2(i3.X, i3.Y), new Vector2(i2.X, i2.Y)), dimensionStyle);
            //fun.dxflinedim(dxf, dim_l3, Math.Round(l3, 2));
            LinearDimension dim_b = new LinearDimension(new Line(new Vector2(u1.X, u1.Y), new Vector2(u2.X, u2.Y)), offset, Pus.Degree(new Vector2(u2.X, u2.Y), new Vector2(u1.X, u1.Y)), dimensionStyle);
            fun.dxflinedim(dxf, dim_b, b);
            //Angular2LineDimension dim_insertAgl = new Angular2LineDimension(new Line(i4, i3), new Line(i4, i1), offset * 0.5, dimensionStyle);
            //dim_insertAgl.UserText = Math.Round(insertAngle * 180 / pi, 2) + "°";
            //dxf.AddEntity(dim_insertAgl);
            Angular2LineDimension dim_cutagl = new Angular2LineDimension(new Line(i4, i1), new Line(new Vector2(i4.X, i4.Y), fun.Polar(new Vector2(i4.X, i4.Y), -pi / 2, 1)), offset * 0.4, dimensionStyle);
            dim_cutagl.UserText = Math.Round(cutagl * 180 / pi, 2) + "°";
            dxf.AddEntity(dim_cutagl);
            //RadialDimension dim_repsilon = new RadialDimension(Pus.GetArcFromPline(minsert, 1), Pus.Degree(i3, i4) - 10, offset * 0.5, dimensionStyle);
            //dim_repsilon.UserText = "rε=" + repsilon;
            //dxf.AddEntity(dim_repsilon);
            //放倒(所有点)尚未平移到下方，因为只能绕着原点k所在轴旋转
            Vector3 rotate = new Vector3(-1, 0, 0);
            double rotateAgl = pi / 2;
            i4 = Pus.Rodrigue(rotate, 1, rotateAgl, i4);
            i3 = Pus.Rodrigue(rotate, 1, rotateAgl, i3);
            i2 = Pus.Rodrigue(rotate, 1, rotateAgl, i2);
            i1 = Pus.Rodrigue(rotate, 1, rotateAgl, i1);
            dt1 = Pus.Rodrigue(rotate, 1, rotateAgl, dt1);
            dt2 = Pus.Rodrigue(rotate, 1, rotateAgl, dt2);
            dt3 = Pus.Rodrigue(rotate, 1, rotateAgl, dt3);
            dt4 = Pus.Rodrigue(rotate, 1, rotateAgl, dt4);
            ii4 = Pus.Rodrigue(rotate, 1, rotateAgl, ii4);
            ii3 = Pus.Rodrigue(rotate, 1, rotateAgl, ii3);
            ii2 = Pus.Rodrigue(rotate, 1, rotateAgl, ii2);
            ii1 = Pus.Rodrigue(rotate, 1, rotateAgl, ii1);

            b1 = Pus.Rodrigue(rotate, 1, rotateAgl, b1);
            b2 = Pus.Rodrigue(rotate, 1, rotateAgl, b2);
            b3 = Pus.Rodrigue(rotate, 1, rotateAgl, b3);
            b4 = Pus.Rodrigue(rotate, 1, rotateAgl, b4);
            b5 = Pus.Rodrigue(rotate, 1, rotateAgl, b5);
            b6 = Pus.Rodrigue(rotate, 1, rotateAgl, b6);
            bdt1 = Pus.Rodrigue(rotate, 1, rotateAgl, bdt1);

            u1 = Pus.Rodrigue(rotate, 1, rotateAgl, u1);
            u2 = Pus.Rodrigue(rotate, 1, rotateAgl, u2);
            u3 = Pus.Rodrigue(rotate, 1, rotateAgl, u3);
            u3p = Pus.Rodrigue(rotate, 1, rotateAgl, u3p);
            u4 = Pus.Rodrigue(rotate, 1, rotateAgl, u4);

            //创建lambds
            rotate = new Vector3(Math.Sin(cutagl - pi / 2), k.Z, Math.Cos(cutagl - pi / 2));
            rotateAgl = lambdas;
            i4 = Pus.Rodrigue(rotate, 1, rotateAgl, i4);
            i3 = Pus.Rodrigue(rotate, 1, rotateAgl, i3);
            i2 = Pus.Rodrigue(rotate, 1, rotateAgl, i2);
            i1 = Pus.Rodrigue(rotate, 1, rotateAgl, i1);
            ii4 = Pus.Rodrigue(rotate, 1, rotateAgl, ii4);
            ii3 = Pus.Rodrigue(rotate, 1, rotateAgl, ii3);
            ii2 = Pus.Rodrigue(rotate, 1, rotateAgl, ii2);
            ii1 = Pus.Rodrigue(rotate, 1, rotateAgl, ii1);
            dt1 = Pus.Rodrigue(rotate, 1, rotateAgl, dt1);
            dt2 = Pus.Rodrigue(rotate, 1, rotateAgl, dt2);
            dt3 = Pus.Rodrigue(rotate, 1, rotateAgl, dt3);
            dt4 = Pus.Rodrigue(rotate, 1, rotateAgl, dt4);

            //创建gamo
            double disi1_i4 = Vector3.Distance(i1, i4);
            rotate = (i1 - i4) / disi1_i4;
            rotateAgl = gamao;
            i4 = Pus.Rodrigue(rotate, 1, rotateAgl, i4);
            i3 = Pus.Rodrigue(rotate, 1, rotateAgl, i3);
            i2 = Pus.Rodrigue(rotate, 1, rotateAgl, i2);
            i1 = Pus.Rodrigue(rotate, 1, rotateAgl, i1);
            ii4 = Pus.Rodrigue(rotate, 1, rotateAgl, ii4);
            ii3 = Pus.Rodrigue(rotate, 1, rotateAgl, ii3);
            ii2 = Pus.Rodrigue(rotate, 1, rotateAgl, ii2);
            ii1 = Pus.Rodrigue(rotate, 1, rotateAgl, ii1);
            dt1 = Pus.Rodrigue(rotate, 1, rotateAgl, dt1);
            dt2 = Pus.Rodrigue(rotate, 1, rotateAgl, dt2);
            dt3 = Pus.Rodrigue(rotate, 1, rotateAgl, dt3);
            dt4 = Pus.Rodrigue(rotate, 1, rotateAgl, dt4);

            //重新计算刀头的点
            Face3d face4dt = new Face3d(dt2, dt3, dt4);
            Vector3 v4dt = u2 - b2;
            dt1 = Pus.Inters(face4dt, new Line(bdt1, bdt1 + v4dt));
            dt2 = Pus.Inters(face4dt, new Line(u3p, u3p + v4dt));
            dt3 = Pus.Inters(face4dt, new Line(b3, b3 + v4dt));
            dt4 = Pus.Inters(face4dt, new Line(b4, b4 + v4dt));

            Face3d face4buttom = new Face3d(b1, b2, b3);
            b5 = Pus.Inters(face4buttom, new Line(ii4, ii4 + v4dt));
            Vector3 bx = Pus.Inters(face4buttom, new Line(ii1, ii1 + v4dt));
            bdt1 = Pus.Inters(face4buttom, new Line(dt1, dt1 + v4dt));

            //平移所有点到下方
            Vector3 voff = new Vector3(0, -b * kscale - offset * 1.5, 0);
            Vector3 mk = Pus.OffsetXY(voff, k);
            Vector3 mi4 = Pus.OffsetXY(voff, i4);
            Vector3 mi3 = Pus.OffsetXY(voff, i3);
            Vector3 mi2 = Pus.OffsetXY(voff, i2);
            Vector3 mi1 = Pus.OffsetXY(voff, i1);
            Vector3 mdt1 = Pus.OffsetXY(voff, dt1);
            Vector3 mdt2 = Pus.OffsetXY(voff, dt2);
            Vector3 mdt3 = Pus.OffsetXY(voff, dt3);
            Vector3 mdt4 = Pus.OffsetXY(voff, dt4);
            Vector3 mii4 = Pus.OffsetXY(voff, ii4);
            Vector3 mii3 = Pus.OffsetXY(voff, ii3);
            Vector3 mii2 = Pus.OffsetXY(voff, ii2);
            Vector3 mii1 = Pus.OffsetXY(voff, ii1);

            Vector3 mb1 = Pus.OffsetXY(voff, b1);
            Vector3 mb2 = Pus.OffsetXY(voff, b2);
            Vector3 mb3 = Pus.OffsetXY(voff, b3);
            Vector3 mb4 = Pus.OffsetXY(voff, b4);
            Vector3 mb5 = Pus.OffsetXY(voff, b5);
            Vector3 mb6 = Pus.OffsetXY(voff, b6);
            Vector3 mbx = Pus.OffsetXY(voff, bx);
            Vector3 mbdt1 = Pus.OffsetXY(voff, bdt1);

            Vector3 mu1 = Pus.OffsetXY(voff, u1);
            Vector3 mu2 = Pus.OffsetXY(voff, u2);
            Vector3 mu3 = Pus.OffsetXY(voff, u3);
            Vector3 mu4 = Pus.OffsetXY(voff, u4);

            LwPolyline lshank = Pus.AddPointsToLwPolyLine(mb1, mu1, mu4, mb6);
            lshank.IsClosed = true;
            fun.PolyFill(dxf, lshank, lineWidth, contour);
            LwPolyline lshank_dt = Pus.AddPointsToLwPolyLine(mdt1, mu4);
            fun.PolyFill(dxf, lshank_dt, lineWidth, contour);
            LwPolyline lshank_dt1 = Pus.AddPointsToLwPolyLine(mdt2, mu3);
            fun.PolyFill(dxf, lshank_dt1, lineWidth, contour);

            LwPolyline lhead = Pus.AddPointsToLwPolyLine(mii4, mb5, mbdt1, mdt1);
            fun.PolyFill(dxf, lhead, lineWidth, contour);
            LwPolyline lhead1 = Pus.AddPointsToLwPolyLine(mbdt1, mb6);
            fun.PolyFill(dxf, lhead1, lineWidth, contour);
            LwPolyline lhead2 = Pus.AddPointsToLwPolyLine(mdt1, mi1);
            fun.PolyFill(dxf, lhead2, lineWidth, contour);
            LwPolyline lhead3 = Pus.AddPointsToLwPolyLine(mdt1, mbdt1);
            fun.PolyFill(dxf, lhead3, lineWidth, contour);
            LwPolyline lhead4 = Pus.AddPointsToLwPolyLine(mbx, mii1);
            fun.PolyFill(dxf, lhead4, lineWidth, contour);
            if (gamao > 0)
            {
                LwPolyline lheadu = Pus.AddPointsToLwPolyLine(mi1, mdt1, mdt2, mdt3, mdt4, mi3);
                fun.PolyFill(dxf, lheadu, lineWidth, contour);

                LwPolyline linsertu = Pus.AddPointsToLwPolyLine(mi4, mi1, mi2, mi3);
                linsertu.IsClosed = true;
                fun.PolyFill(dxf, linsertu, lineWidth, cutting);
            }

            LwPolyline linsertf = Pus.AddPointsToLwPolyLine(mi4, mii4, mii1, mi1);
            linsertf.IsClosed = true;
            fun.PolyFill(dxf, linsertf, lineWidth, cutting);
            //l视图标注
            LinearDimension dim_h1 = new LinearDimension(new Line(new Vector2(mk.X, mk.Y), new Vector2(mb5.X, mb5.Y)), offset * 0.5, Pus.Degree(b1, u1), dimensionStyle);
            fun.dxflinedim(dxf, dim_h1, h1);
            LinearDimension dim_h2 = new LinearDimension(new Line(new Vector2(mu1.X, mu1.Y), new Vector2(mb1.X, mb1.Y)), offset, Pus.Degree(u1, b1), dimensionStyle);
            fun.dxflinedim(dxf, dim_h2, h2);
            if (lambdas == 0)
                Pus.NeedleDim(dxf, new Line(new Vector2(mi4.X, mi4.Y), fun.Polar(new Vector2(mi4.X, mi4.Y), pi / 180, 1)), new Line(mi4, mi4 + mu4 - mu2), kscale * offset, "λs=0°", dimensionStyle);
            else
                Pus.NeedleDim(dxf, new Line(mi4, mi1), new Line(mi4, mi4 + mu4 - mu2), kscale * offset, "λs=" + Math.Round(lambdas * 180 / pi, 2) + "°", dimensionStyle);
            //左视图
            //所有点移动到原点
            //立正
            rotate = new Vector3(1, 0, 0);
            rotateAgl = pi / 2;
            Vector3 zi4 = Pus.Rodrigue(rotate, 1, rotateAgl, i4);
            Vector3 zi3 = Pus.Rodrigue(rotate, 1, rotateAgl, i3);
            Vector3 zi2 = Pus.Rodrigue(rotate, 1, rotateAgl, i2);
            Vector3 zi1 = Pus.Rodrigue(rotate, 1, rotateAgl, i1);
            Vector3 zdt1 = Pus.Rodrigue(rotate, 1, rotateAgl, dt1);
            Vector3 zdt2 = Pus.Rodrigue(rotate, 1, rotateAgl, dt2);
            Vector3 zdt3 = Pus.Rodrigue(rotate, 1, rotateAgl, dt3);
            Vector3 zdt4 = Pus.Rodrigue(rotate, 1, rotateAgl, dt4);

            Vector3 zii4 = Pus.Rodrigue(rotate, 1, rotateAgl, ii4);
            Vector3 zii3 = Pus.Rodrigue(rotate, 1, rotateAgl, ii3);
            Vector3 zii2 = Pus.Rodrigue(rotate, 1, rotateAgl, ii2);
            Vector3 zii1 = Pus.Rodrigue(rotate, 1, rotateAgl, ii1);

            Vector3 zb1 = Pus.Rodrigue(rotate, 1, rotateAgl, b1);
            Vector3 zb2 = Pus.Rodrigue(rotate, 1, rotateAgl, b2);
            Vector3 zb3 = Pus.Rodrigue(rotate, 1, rotateAgl, b3);
            Vector3 zb4 = Pus.Rodrigue(rotate, 1, rotateAgl, b4);
            Vector3 zb5 = Pus.Rodrigue(rotate, 1, rotateAgl, b5);
            Vector3 zb6 = Pus.Rodrigue(rotate, 1, rotateAgl, b6);
            Vector3 zbx = Pus.Rodrigue(rotate, 1, rotateAgl, bx);
            Vector3 zbdt1 = Pus.Rodrigue(rotate, 1, rotateAgl, bdt1);

            Vector3 zu1 = Pus.Rodrigue(rotate, 1, rotateAgl, u1);
            Vector3 zu2 = Pus.Rodrigue(rotate, 1, rotateAgl, u2);
            Vector3 zu3 = Pus.Rodrigue(rotate, 1, rotateAgl, u3);
            Vector3 zu4 = Pus.Rodrigue(rotate, 1, rotateAgl, u4);

            //绕y转，露出左面
            rotate = new Vector3(0, 1, 0);
            rotateAgl = pi / 2;
            zi4 = Pus.Rodrigue(rotate, 1, rotateAgl, zi4);
            zi3 = Pus.Rodrigue(rotate, 1, rotateAgl, zi3);
            zi2 = Pus.Rodrigue(rotate, 1, rotateAgl, zi2);
            zi1 = Pus.Rodrigue(rotate, 1, rotateAgl, zi1);
            zdt1 = Pus.Rodrigue(rotate, 1, rotateAgl, zdt1);
            zdt2 = Pus.Rodrigue(rotate, 1, rotateAgl, zdt2);
            zdt3 = Pus.Rodrigue(rotate, 1, rotateAgl, zdt3);
            zdt4 = Pus.Rodrigue(rotate, 1, rotateAgl, zdt4);

            zii4 = Pus.Rodrigue(rotate, 1, rotateAgl, zii4);
            zii3 = Pus.Rodrigue(rotate, 1, rotateAgl, zii3);
            zii2 = Pus.Rodrigue(rotate, 1, rotateAgl, zii2);
            zii1 = Pus.Rodrigue(rotate, 1, rotateAgl, zii1);

            zb1 = Pus.Rodrigue(rotate, 1, rotateAgl, zb1);
            zb2 = Pus.Rodrigue(rotate, 1, rotateAgl, zb2);
            zb3 = Pus.Rodrigue(rotate, 1, rotateAgl, zb3);
            zb4 = Pus.Rodrigue(rotate, 1, rotateAgl, zb4);
            zb5 = Pus.Rodrigue(rotate, 1, rotateAgl, zb5);
            zb6 = Pus.Rodrigue(rotate, 1, rotateAgl, zb6);
            zbx = Pus.Rodrigue(rotate, 1, rotateAgl, zbx);
            zbdt1 = Pus.Rodrigue(rotate, 1, rotateAgl, zbdt1);

            zu1 = Pus.Rodrigue(rotate, 1, rotateAgl, zu1);
            zu2 = Pus.Rodrigue(rotate, 1, rotateAgl, zu2);
            zu3 = Pus.Rodrigue(rotate, 1, rotateAgl, zu3);
            zu4 = Pus.Rodrigue(rotate, 1, rotateAgl, zu4);

            //平移
            voff = new Vector3(-b * kscale - offset * 2, 0, 0);
            zi4 = Pus.OffsetXY(voff, zi4);
            zi3 = Pus.OffsetXY(voff, zi3);
            zi2 = Pus.OffsetXY(voff, zi2);
            zi1 = Pus.OffsetXY(voff, zi1);
            zdt1 = Pus.OffsetXY(voff, zdt1);
            zdt2 = Pus.OffsetXY(voff, zdt2);
            zdt3 = Pus.OffsetXY(voff, zdt3);
            zdt4 = Pus.OffsetXY(voff, zdt4);

            zii4 = Pus.OffsetXY(voff, zii4);
            zii3 = Pus.OffsetXY(voff, zii3);
            zii2 = Pus.OffsetXY(voff, zii2);
            zii1 = Pus.OffsetXY(voff, zii1);

            zb1 = Pus.OffsetXY(voff, zb1);
            zb2 = Pus.OffsetXY(voff, zb2);
            zb3 = Pus.OffsetXY(voff, zb3);
            zb4 = Pus.OffsetXY(voff, zb4);
            zb5 = Pus.OffsetXY(voff, zb5);
            zb6 = Pus.OffsetXY(voff, zb6);
            zbx = Pus.OffsetXY(voff, zbx);
            zbdt1 = Pus.OffsetXY(voff, zbdt1);

            zu1 = Pus.OffsetXY(voff, zu1);
            zu2 = Pus.OffsetXY(voff, zu2);
            zu3 = Pus.OffsetXY(voff, zu3);
            zu4 = Pus.OffsetXY(voff, zu4);

            //左视图绘制
            LwPolyline zshank = Pus.AddPointsToLwPolyLine(zii4, zb5, zb4, zb3, zdt3, zdt4, zi3);
            fun.PolyFill(dxf, zshank, lineWidth, contour);
            LwPolyline zshank2 = Pus.AddPointsToLwPolyLine(zb4, zdt4);
            fun.PolyFill(dxf, zshank2, lineWidth, contour);
            if (lambdas > 0)
            {
                LwPolyline zshank1 = Pus.AddPointsToLwPolyLine(zdt3, zdt2, zdt1, zi1);
                fun.PolyFill(dxf, zshank1, lineWidth, contour);

                LwPolyline zinsert = Pus.AddPointsToLwPolyLine(zi4, zi1, zi2, zi3);
                zinsert.IsClosed = true;
                fun.PolyFill(dxf, zinsert, lineWidth, cutting);
            }

            LwPolyline zlen1 = Pus.AddPointsToLwPolyLine(zi3, zii3, zii4, zi4);
            zlen1.IsClosed = true;
            fun.PolyFill(dxf, zlen1, lineWidth, cutting);

            if (cutagl < pi / 2)
            {
                LwPolyline zlen2 = Pus.AddPointsToLwPolyLine(zii4, zii1, zi1, zi4);
                fun.PolyFill(dxf, zlen2, lineWidth, cutting);
            }
            //if (zdt1.Y > zu4.Y)
            //{
            //    Vector2 visible = Pus.IntersOnP(zi4, zi1, zb4, zu4);
            //    LwPolyline visiLine = Pus.AddPointsToLwPolyLine(zdt1, zu4);
            //    Pus.AddPointsToLwPolyLine(visiLine, visible);
            //    fun.PolyFill(dxf, visiLine, lineWidth, contour);
            //}
            //左视图标注
            //刃倾角
            if (gamao == 0)
                Pus.NeedleDim(dxf, new Line(new Vector2(zi4.X, zi4.Y), fun.Polar(new Vector2(zi4.X, zi4.Y), Pus.AngleOnP(zi3, zi4) + pi / 180, 1)), new Line(zi3, zi4), offset * 1.5, "γo=0°", dimensionStyle);
            else
                Pus.NeedleDim(dxf, new Line(zi3, zi4), new Line(new Vector2(zi4.X, zi4.Y), fun.Polar(new Vector2(zi4.X, zi4.Y), Pus.AngleOnP(zi3, zi4) + gamao, 1)), offset * 1.5, "γo=" + Math.Round(lambdas * 180 / pi, 2) + "°", dimensionStyle);

            //LinearDimension dim_s = new LinearDimension(new Line(zi4, zii4), offset, Pus.Degree(zi4, zi3) + 90, dimensionStyle);
            //fun.dxflinedim(dxf, dim_s, s);

            //后角
            if (alphan == 0)
                Pus.NeedleDim(dxf, new Line(zi4, zii4), new Line(new Vector2(zi4.X, zi4.Y), fun.Polar(new Vector2(zi4.X, zi4.Y), Pus.AngleOnP(zi4, zii4) + pi / 180, 1)), offset + h1 * kscale, "αn=0°", dimensionStyle);
            else
                Pus.NeedleDim(dxf, new Line(zi4, zii4), new Line(new Vector2(zi4.X, zi4.Y), fun.Polar(new Vector2(zi4.X, zi4.Y), Pus.AngleOnP(zi4, zii4) + alphan, 1)), offset + h1 * kscale, "αn=" + Math.Round(alphan * 180 / pi, 2) + "°", dimensionStyle);
            //图框
            if (Convert.ToDouble(data["isframe"]) == 1)
            {
                Vector2 c4c = new Vector2((b2.X + zb3.X) / 2, (b2.Y + mu1.Y) / 2);
                Dictionary<string, Vector2> positions = Frame.frameA3X(dxf, new Vector2(c4c.X - 420 / 2, c4c.Y + 297 / 2), new Dictionary<string, object>());
                fun.writetextofC(dxf, kscale + ":1", positions["比例"], 3.5, 0, 0.6, 3);
            }

            dxf.DrawingVariables.AcadVer = DxfVersion.AutoCad2007;
            dxf.Save(path);
        }
        public static void StyleH_InsertV(Dictionary<string, Object> data)
        {

            DxfDocument dxf = new DxfDocument();
            Layer contour = new Layer("contour") { Color = AciColor.Cyan };    //1,轮廓层
            Layer cutting = new Layer("cutting") { Color = AciColor.Red };    //切削层

            string path = Convert.ToString(data["path"]);
            //参数名称取自ISO 5610-2
            double b = 12;
            double l1 = 70;
            double l2 = 25;
            double f = 16;
            double l3 = 11.1;
            double h2 = 12;
            double h1 = 12;
            double s = 3.18;
            double insertAngle = 35 * pi / 180;
            double alphan = 7 * pi / 180;
            double cutagl = 107.5 * pi / 180;
            double lambdas = 0;
            double gamao = 0;
            double repsilon = 0;
            #region
            try
            {
                if (data["re"] != null)
                    repsilon = Convert.ToDouble(data["re"]);
                if (repsilon <= 0)
                    repsilon = 0.01;
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["lams"] != null)
                    lambdas = Math.Abs(Convert.ToDouble(data["lams"]) * pi / 180);
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["gamo"] != null)
                    gamao = Math.Abs(Convert.ToDouble(data["gamo"]) * pi / 180);
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["b"] != null)
                    b = Convert.ToDouble(data["b"]);
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["s"] != null)
                    s = Convert.ToDouble(data["s"]);
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["lf"] != null)
                    l1 = Convert.ToDouble(data["lf"]);
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["lh"] != null)
                    l2 = Convert.ToDouble(data["lh"]);
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["wf"] != null)
                    f = Convert.ToDouble(data["wf"]);
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["h"] != null)
                    h2 = Convert.ToDouble(data["h"]);
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["hf"] != null)
                    h1 = Convert.ToDouble(data["hf"]);
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["epsr"] != null)
                    insertAngle = Convert.ToDouble(data["epsr"]) * pi / 180;
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["kapr"] != null)
                    cutagl = Convert.ToDouble(data["kapr"]) * pi / 180;
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["an"] != null)
                    alphan = Convert.ToDouble(data["an"]) * pi / 180;
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["ic"] != null)
                    l3 = Pus.GetLByIC(Convert.ToDouble(data["ic"]), insertAngle);
            }
            catch (KeyNotFoundException) { }
            #endregion
            double kscale = 1;
            if (l1 >= 120)
                kscale = 1;
            else
                kscale = 1.5;
            double lineWidth = 1;
            //k点位置恒定
            Vector3 k = new Vector3(0, 0, 0);
            Vector3 b2 = new Vector3(k.X + l1, k.Y + f, k.Z - h1);
            Vector3 b1 = new Vector3(b2.X, b2.Y - b, b2.Z);
            Vector3 b6 = new Vector3(k.X + l2, b1.Y, b1.Z);

            //刀杆顶面
            Vector3 u1 = new Vector3(b1.X, b1.Y, b1.Z + h2);
            Vector3 u2 = new Vector3(b2.X, b2.Y, b2.Z + h2);
            Vector3 u3 = new Vector3(b6.X, b2.Y, b2.Z + h2);
            double guai = kscale;
            Vector3 u3p = new Vector3(u3.X - guai, u3.Y, u3.Z);
            Vector3 u4 = new Vector3(b6.X, b6.Y, b6.Z + h2);
            Vector3 u4p = new Vector3(u4.X - guai, u4.Y, u4.Z);

            //Kp=fun.polar(K,0,r/tan((pi-kapr)/2)-r)
            //i4=fun.polar(Kp,kapr-pi,r/tan(epsr/2)-r/tan((pi-kapr)/2))
            Vector2 kp = fun.Polar(Vector2.Zero, 0, repsilon / Math.Tan((pi - cutagl) / 2) - repsilon);
            Vector2 twoi4 = fun.Polar(kp, cutagl - pi, repsilon / Math.Tan(insertAngle / 2) - repsilon / Math.Tan((pi - cutagl) / 2));
            Vector2[] twois = Pus.DiamondPoints(twoi4, l3, insertAngle, true, cutagl);
            Vector2 twoi1 = twois[1];
            Vector2 twoi2 = twois[2];
            Vector2 twoi3 = twois[3];
            double theoffset = Math.Tan(alphan) * s;
            Vector2[] twoiis = Pus.OffsetPoints(theoffset, twois);
            Vector2 twoii4 = twoiis[0];
            Vector2 twoii3 = twoiis[3];
            Vector2 twoii1 = twoiis[1];
            Vector2 twoii2 = twoiis[2];

            //刀头面
            Vector3 i4 = new Vector3(twoi4.X, twoi4.Y, k.Z);
            Vector3 i3 = new Vector3(twoi3.X, twoi3.Y, k.Z);
            Vector3 i2 = new Vector3(twoi2.X, twoi2.Y, k.Z);
            Vector3 i1 = new Vector3(twoi1.X, twoi1.Y, k.Z);
            Vector2 cnm = Pus.IntersOnP(i1, new Vector3(i1.X + 1, i1.Y, i1.Z), u3p, u4p);
            Vector3 dt1 = new Vector3(cnm.X, cnm.Y, u4.Z);
            Vector3 dt2 = u3p;
            Vector2 xx = Pus.IntersOnP(i3, i4, u2, u3);
            Vector3 dt4 = Pus.KPoint(i3, new Vector3(xx.X, xx.Y, u3.Z), 0.7);
            Vector3 dt3 = Pus.KPoint(u3, new Vector3(xx.X, xx.Y, u3.Z), 0.85);

            Vector3 bdt1 = new Vector3(dt1.X, dt1.Y, b1.Z);
            Vector3 b5 = new Vector3(twoii4.X, twoii4.Y, b1.Z);
            Vector3 b4 = new Vector3(dt4.X, dt4.Y, b1.Z);
            Vector3 b3 = new Vector3(dt3.X, dt3.Y, b1.Z);

            Vector3 ii4 = new Vector3(twoii4.X, twoii4.Y, k.Z - s);
            Vector3 ii3 = new Vector3(twoii3.X, twoii3.Y, k.Z - s);
            Vector3 ii1 = new Vector3(twoii1.X, twoii1.Y, k.Z - s);
            Vector3 ii2 = new Vector3(twoii2.X, twoii2.Y, k.Z - s);

            i4 = Pus.LinearTrans(kscale, i4);
            i3 = Pus.LinearTrans(kscale, i3);
            i2 = Pus.LinearTrans(kscale, i2);
            i1 = Pus.LinearTrans(kscale, i1);
            dt1 = Pus.LinearTrans(kscale, dt1);
            dt2 = Pus.LinearTrans(kscale, dt2);
            dt3 = Pus.LinearTrans(kscale, dt3);
            dt4 = Pus.LinearTrans(kscale, dt4);

            ii4 = Pus.LinearTrans(kscale, ii4);
            ii3 = Pus.LinearTrans(kscale, ii3);
            ii2 = Pus.LinearTrans(kscale, ii2);
            ii1 = Pus.LinearTrans(kscale, ii1);

            b1 = Pus.LinearTrans(kscale, b1);
            b2 = Pus.LinearTrans(kscale, b2);
            b3 = Pus.LinearTrans(kscale, b3);
            b4 = Pus.LinearTrans(kscale, b4);
            b5 = Pus.LinearTrans(kscale, b5);
            b6 = Pus.LinearTrans(kscale, b6);
            bdt1 = Pus.LinearTrans(kscale, bdt1);

            u1 = Pus.LinearTrans(kscale, u1);
            u2 = Pus.LinearTrans(kscale, u2);
            u3 = Pus.LinearTrans(kscale, u3);
            u3p = Pus.LinearTrans(kscale, u3p);
            u4 = Pus.LinearTrans(kscale, u4);


            //主视图
            LwPolyline mshank = Pus.AddPointsToLwPolyLine(u1, u2, u3, u4);
            mshank.IsClosed = true;
            fun.PolyFill(dxf, mshank, lineWidth, contour);

            LwPolyline minsert = Pus.AddPointsToLwPolyLine(i4, i1, i2, i3);
            minsert.IsClosed = true;
            Pus.AglToArc(minsert, repsilon);

            LwPolyline mhead = Pus.AddPointsToLwPolyLine(i3, i2, i1, dt1, dt2, dt3, dt4, i3);
            mhead.IsClosed = true;
            fun.PolyFill(dxf, mhead, lineWidth, contour);
            LwPolyline mheadc1 = Pus.AddPointsToLwPolyLine(dt1, u4);
            fun.PolyFill(dxf, mheadc1, lineWidth, contour);
            LwPolyline mheadc2 = Pus.AddPointsToLwPolyLine(dt2, u3);
            fun.PolyFill(dxf, mheadc2, lineWidth, contour);

            fun.PolyFill(dxf, minsert, lineWidth, cutting);
            //m视图标注
            DimensionStyle dimensionStyle = new DimensionStyle("mystyle");
            dimensionStyle.ArrowSize = kscale * 1.2;
            dimensionStyle.DimArrow1 = DimensionArrowhead.Closedfilled;
            dimensionStyle.DimArrow2 = DimensionArrowhead.Closedfilled;
            dimensionStyle.TextHeight = kscale;
            dimensionStyle.TextOffset = kscale / 2;
            double offset = 7 * kscale;
            LinearDimension dim_f = new LinearDimension(new Line(new Vector2(k.X, k.Y), new Vector2(b3.X, b3.Y)), offset * 1.5, Pus.Degree(b1, b2), dimensionStyle);
            fun.dxflinedim(dxf, dim_f, f);
            LinearDimension dim_l1 = new LinearDimension(new Line(new Vector2(k.X, k.Y), new Vector2(b1.X, b1.Y)), offset * 1.5, Pus.Degree(new Vector2(b1.X, b1.Y), new Vector2(b6.X, b6.Y)), dimensionStyle);
            fun.dxflinedim(dxf, dim_l1, l1);
            LinearDimension dim_l2 = new LinearDimension(new Line(new Vector2(k.X, k.Y), new Vector2(u4.X, u4.Y)), offset, Pus.Degree(new Vector2(u1.X, u1.Y), new Vector2(u4.X, u4.Y)), dimensionStyle);
            fun.dxflinedim(dxf, dim_l2, l2);
            //LinearDimension dim_l3 = new LinearDimension(new Line(i2, i3), offset, Pus.Degree(new Vector2(i3.X, i3.Y), new Vector2(i2.X, i2.Y)), dimensionStyle);
            //fun.dxflinedim(dxf, dim_l3, Math.Round(l3, 2));
            LinearDimension dim_b = new LinearDimension(new Line(new Vector2(u1.X, u1.Y), new Vector2(u2.X, u2.Y)), offset, Pus.Degree(new Vector2(u2.X, u2.Y), new Vector2(u1.X, u1.Y)), dimensionStyle);
            fun.dxflinedim(dxf, dim_b, b);
            //Angular2LineDimension dim_insertAgl = new Angular2LineDimension(new Line(i4, i3), new Line(i4, i1), offset * 0.5, dimensionStyle);
            //dim_insertAgl.UserText = Math.Round(insertAngle * 180 / pi, 2) + "°";
            //dxf.AddEntity(dim_insertAgl);
            Angular2LineDimension dim_cutagl = new Angular2LineDimension(new Line(i4, i1), new Line(new Vector2(i4.X, i4.Y), fun.Polar(new Vector2(i4.X, i4.Y), -pi / 2, 1)), offset * 0.4, dimensionStyle);
            dim_cutagl.UserText = Math.Round(cutagl * 180 / pi, 2) + "°";
            dxf.AddEntity(dim_cutagl);
            //RadialDimension dim_repsilon = new RadialDimension(Pus.GetArcFromPline(minsert, 1), Pus.Degree(i3, i4) - 10, offset * 0.5, dimensionStyle);
            //dim_repsilon.UserText = "rε=" + repsilon;
            //dxf.AddEntity(dim_repsilon);
            //放倒(所有点)尚未平移到下方，因为只能绕着原点k所在轴旋转
            Vector3 rotate = new Vector3(-1, 0, 0);
            double rotateAgl = pi / 2;
            i4 = Pus.Rodrigue(rotate, 1, rotateAgl, i4);
            i3 = Pus.Rodrigue(rotate, 1, rotateAgl, i3);
            i2 = Pus.Rodrigue(rotate, 1, rotateAgl, i2);
            i1 = Pus.Rodrigue(rotate, 1, rotateAgl, i1);
            dt1 = Pus.Rodrigue(rotate, 1, rotateAgl, dt1);
            dt2 = Pus.Rodrigue(rotate, 1, rotateAgl, dt2);
            dt3 = Pus.Rodrigue(rotate, 1, rotateAgl, dt3);
            dt4 = Pus.Rodrigue(rotate, 1, rotateAgl, dt4);
            ii4 = Pus.Rodrigue(rotate, 1, rotateAgl, ii4);
            ii3 = Pus.Rodrigue(rotate, 1, rotateAgl, ii3);
            ii2 = Pus.Rodrigue(rotate, 1, rotateAgl, ii2);
            ii1 = Pus.Rodrigue(rotate, 1, rotateAgl, ii1);

            b1 = Pus.Rodrigue(rotate, 1, rotateAgl, b1);
            b2 = Pus.Rodrigue(rotate, 1, rotateAgl, b2);
            b3 = Pus.Rodrigue(rotate, 1, rotateAgl, b3);
            b4 = Pus.Rodrigue(rotate, 1, rotateAgl, b4);
            b5 = Pus.Rodrigue(rotate, 1, rotateAgl, b5);
            b6 = Pus.Rodrigue(rotate, 1, rotateAgl, b6);
            bdt1 = Pus.Rodrigue(rotate, 1, rotateAgl, bdt1);

            u1 = Pus.Rodrigue(rotate, 1, rotateAgl, u1);
            u2 = Pus.Rodrigue(rotate, 1, rotateAgl, u2);
            u3 = Pus.Rodrigue(rotate, 1, rotateAgl, u3);
            u3p = Pus.Rodrigue(rotate, 1, rotateAgl, u3p);
            u4 = Pus.Rodrigue(rotate, 1, rotateAgl, u4);

            //创建lambds
            rotate = new Vector3(Math.Sin(cutagl - pi / 2), k.Z, Math.Cos(cutagl - pi / 2));
            rotateAgl = lambdas;
            i4 = Pus.Rodrigue(rotate, 1, rotateAgl, i4);
            i3 = Pus.Rodrigue(rotate, 1, rotateAgl, i3);
            i2 = Pus.Rodrigue(rotate, 1, rotateAgl, i2);
            i1 = Pus.Rodrigue(rotate, 1, rotateAgl, i1);
            ii4 = Pus.Rodrigue(rotate, 1, rotateAgl, ii4);
            ii3 = Pus.Rodrigue(rotate, 1, rotateAgl, ii3);
            ii2 = Pus.Rodrigue(rotate, 1, rotateAgl, ii2);
            ii1 = Pus.Rodrigue(rotate, 1, rotateAgl, ii1);
            dt1 = Pus.Rodrigue(rotate, 1, rotateAgl, dt1);
            dt2 = Pus.Rodrigue(rotate, 1, rotateAgl, dt2);
            dt3 = Pus.Rodrigue(rotate, 1, rotateAgl, dt3);
            dt4 = Pus.Rodrigue(rotate, 1, rotateAgl, dt4);

            //创建gamo
            double disi1_i4 = Vector3.Distance(i1, i4);
            rotate = (i1 - i4) / disi1_i4;
            rotateAgl = gamao;
            i4 = Pus.Rodrigue(rotate, 1, rotateAgl, i4);
            i3 = Pus.Rodrigue(rotate, 1, rotateAgl, i3);
            i2 = Pus.Rodrigue(rotate, 1, rotateAgl, i2);
            i1 = Pus.Rodrigue(rotate, 1, rotateAgl, i1);
            ii4 = Pus.Rodrigue(rotate, 1, rotateAgl, ii4);
            ii3 = Pus.Rodrigue(rotate, 1, rotateAgl, ii3);
            ii2 = Pus.Rodrigue(rotate, 1, rotateAgl, ii2);
            ii1 = Pus.Rodrigue(rotate, 1, rotateAgl, ii1);
            dt1 = Pus.Rodrigue(rotate, 1, rotateAgl, dt1);
            dt2 = Pus.Rodrigue(rotate, 1, rotateAgl, dt2);
            dt3 = Pus.Rodrigue(rotate, 1, rotateAgl, dt3);
            dt4 = Pus.Rodrigue(rotate, 1, rotateAgl, dt4);

            //重新计算刀头的点
            Face3d face4dt = new Face3d(dt2, dt3, dt4);
            Vector3 v4dt = u2 - b2;
            dt1 = Pus.Inters(face4dt, new Line(bdt1, bdt1 + v4dt));
            dt2 = Pus.Inters(face4dt, new Line(u3p, u3p + v4dt));
            dt3 = Pus.Inters(face4dt, new Line(b3, b3 + v4dt));
            dt4 = Pus.Inters(face4dt, new Line(b4, b4 + v4dt));

            Face3d face4buttom = new Face3d(b1, b2, b3);
            b5 = Pus.Inters(face4buttom, new Line(ii4, ii4 + v4dt));
            Vector3 bx = Pus.Inters(face4buttom, new Line(ii1, ii1 + v4dt));
            bdt1 = Pus.Inters(face4buttom, new Line(dt1, dt1 + v4dt));

            //平移所有点到下方
            Vector3 voff = new Vector3(0, -b * kscale - offset * 1.5, 0);
            Vector3 mk = Pus.OffsetXY(voff, k);
            Vector3 mi4 = Pus.OffsetXY(voff, i4);
            Vector3 mi3 = Pus.OffsetXY(voff, i3);
            Vector3 mi2 = Pus.OffsetXY(voff, i2);
            Vector3 mi1 = Pus.OffsetXY(voff, i1);
            Vector3 mdt1 = Pus.OffsetXY(voff, dt1);
            Vector3 mdt2 = Pus.OffsetXY(voff, dt2);
            Vector3 mdt3 = Pus.OffsetXY(voff, dt3);
            Vector3 mdt4 = Pus.OffsetXY(voff, dt4);
            Vector3 mii4 = Pus.OffsetXY(voff, ii4);
            Vector3 mii3 = Pus.OffsetXY(voff, ii3);
            Vector3 mii2 = Pus.OffsetXY(voff, ii2);
            Vector3 mii1 = Pus.OffsetXY(voff, ii1);

            Vector3 mb1 = Pus.OffsetXY(voff, b1);
            Vector3 mb2 = Pus.OffsetXY(voff, b2);
            Vector3 mb3 = Pus.OffsetXY(voff, b3);
            Vector3 mb4 = Pus.OffsetXY(voff, b4);
            Vector3 mb5 = Pus.OffsetXY(voff, b5);
            Vector3 mb6 = Pus.OffsetXY(voff, b6);
            Vector3 mbx = Pus.OffsetXY(voff, bx);
            Vector3 mbdt1 = Pus.OffsetXY(voff, bdt1);

            Vector3 mu1 = Pus.OffsetXY(voff, u1);
            Vector3 mu2 = Pus.OffsetXY(voff, u2);
            Vector3 mu3 = Pus.OffsetXY(voff, u3);
            Vector3 mu4 = Pus.OffsetXY(voff, u4);

            LwPolyline lshank = Pus.AddPointsToLwPolyLine(mb1, mu1, mu4, mb6);
            lshank.IsClosed = true;
            fun.PolyFill(dxf, lshank, lineWidth, contour);
            LwPolyline lshank_dt = Pus.AddPointsToLwPolyLine(mdt1, mu4);
            fun.PolyFill(dxf, lshank_dt, lineWidth, contour);
            LwPolyline lshank_dt1 = Pus.AddPointsToLwPolyLine(mdt2, mu3);
            fun.PolyFill(dxf, lshank_dt1, lineWidth, contour);

            LwPolyline lhead = Pus.AddPointsToLwPolyLine(mii4, mb5, mbdt1, mdt1);
            fun.PolyFill(dxf, lhead, lineWidth, contour);
            LwPolyline lhead1 = Pus.AddPointsToLwPolyLine(mbdt1, mb6);
            fun.PolyFill(dxf, lhead1, lineWidth, contour);
            LwPolyline lhead2 = Pus.AddPointsToLwPolyLine(mdt1, mi1);
            fun.PolyFill(dxf, lhead2, lineWidth, contour);
            LwPolyline lhead3 = Pus.AddPointsToLwPolyLine(mdt1, mbdt1);
            fun.PolyFill(dxf, lhead3, lineWidth, contour);
            LwPolyline lhead4 = Pus.AddPointsToLwPolyLine(mbx, mii1);
            fun.PolyFill(dxf, lhead4, lineWidth, contour);
            if (gamao > 0)
            {
                LwPolyline lheadu = Pus.AddPointsToLwPolyLine(mi1, mdt1, mdt2, mdt3, mdt4, mi3);
                fun.PolyFill(dxf, lheadu, lineWidth, contour);

                LwPolyline linsertu = Pus.AddPointsToLwPolyLine(mi4, mi1, mi2, mi3);
                linsertu.IsClosed = true;
                fun.PolyFill(dxf, linsertu, lineWidth, cutting);
            }

            LwPolyline linsertf = Pus.AddPointsToLwPolyLine(mi4, mii4, mii1, mi1);
            linsertf.IsClosed = true;
            fun.PolyFill(dxf, linsertf, lineWidth, cutting);
            //l视图标注
            LinearDimension dim_h1 = new LinearDimension(new Line(new Vector2(mk.X, mk.Y), new Vector2(mb5.X, mb5.Y)), offset * 0.5, Pus.Degree(b1, u1), dimensionStyle);
            fun.dxflinedim(dxf, dim_h1, h1);
            LinearDimension dim_h2 = new LinearDimension(new Line(new Vector2(mu1.X, mu1.Y), new Vector2(mb1.X, mb1.Y)), offset, Pus.Degree(u1, b1), dimensionStyle);
            fun.dxflinedim(dxf, dim_h2, h2);
            if (lambdas == 0)
                Pus.NeedleDim(dxf, new Line(new Vector2(mi4.X, mi4.Y), fun.Polar(new Vector2(mi4.X, mi4.Y), pi / 180, 1)), new Line(mi4, mi4 + mu4 - mu2), kscale * offset, "λs=0°", dimensionStyle);
            else
                Pus.NeedleDim(dxf, new Line(mi4, mi1), new Line(mi4, mi4 + mu4 - mu2), kscale * offset, "λs=" + Math.Round(lambdas * 180 / pi, 2) + "°", dimensionStyle);
            //左视图
            //所有点移动到原点
            //立正
            rotate = new Vector3(1, 0, 0);
            rotateAgl = pi / 2;
            Vector3 zi4 = Pus.Rodrigue(rotate, 1, rotateAgl, i4);
            Vector3 zi3 = Pus.Rodrigue(rotate, 1, rotateAgl, i3);
            Vector3 zi2 = Pus.Rodrigue(rotate, 1, rotateAgl, i2);
            Vector3 zi1 = Pus.Rodrigue(rotate, 1, rotateAgl, i1);
            Vector3 zdt1 = Pus.Rodrigue(rotate, 1, rotateAgl, dt1);
            Vector3 zdt2 = Pus.Rodrigue(rotate, 1, rotateAgl, dt2);
            Vector3 zdt3 = Pus.Rodrigue(rotate, 1, rotateAgl, dt3);
            Vector3 zdt4 = Pus.Rodrigue(rotate, 1, rotateAgl, dt4);

            Vector3 zii4 = Pus.Rodrigue(rotate, 1, rotateAgl, ii4);
            Vector3 zii3 = Pus.Rodrigue(rotate, 1, rotateAgl, ii3);
            Vector3 zii2 = Pus.Rodrigue(rotate, 1, rotateAgl, ii2);
            Vector3 zii1 = Pus.Rodrigue(rotate, 1, rotateAgl, ii1);

            Vector3 zb1 = Pus.Rodrigue(rotate, 1, rotateAgl, b1);
            Vector3 zb2 = Pus.Rodrigue(rotate, 1, rotateAgl, b2);
            Vector3 zb3 = Pus.Rodrigue(rotate, 1, rotateAgl, b3);
            Vector3 zb4 = Pus.Rodrigue(rotate, 1, rotateAgl, b4);
            Vector3 zb5 = Pus.Rodrigue(rotate, 1, rotateAgl, b5);
            Vector3 zb6 = Pus.Rodrigue(rotate, 1, rotateAgl, b6);
            Vector3 zbx = Pus.Rodrigue(rotate, 1, rotateAgl, bx);
            Vector3 zbdt1 = Pus.Rodrigue(rotate, 1, rotateAgl, bdt1);

            Vector3 zu1 = Pus.Rodrigue(rotate, 1, rotateAgl, u1);
            Vector3 zu2 = Pus.Rodrigue(rotate, 1, rotateAgl, u2);
            Vector3 zu3 = Pus.Rodrigue(rotate, 1, rotateAgl, u3);
            Vector3 zu4 = Pus.Rodrigue(rotate, 1, rotateAgl, u4);

            //绕y转，露出左面
            rotate = new Vector3(0, 1, 0);
            rotateAgl = pi / 2;
            zi4 = Pus.Rodrigue(rotate, 1, rotateAgl, zi4);
            zi3 = Pus.Rodrigue(rotate, 1, rotateAgl, zi3);
            zi2 = Pus.Rodrigue(rotate, 1, rotateAgl, zi2);
            zi1 = Pus.Rodrigue(rotate, 1, rotateAgl, zi1);
            zdt1 = Pus.Rodrigue(rotate, 1, rotateAgl, zdt1);
            zdt2 = Pus.Rodrigue(rotate, 1, rotateAgl, zdt2);
            zdt3 = Pus.Rodrigue(rotate, 1, rotateAgl, zdt3);
            zdt4 = Pus.Rodrigue(rotate, 1, rotateAgl, zdt4);

            zii4 = Pus.Rodrigue(rotate, 1, rotateAgl, zii4);
            zii3 = Pus.Rodrigue(rotate, 1, rotateAgl, zii3);
            zii2 = Pus.Rodrigue(rotate, 1, rotateAgl, zii2);
            zii1 = Pus.Rodrigue(rotate, 1, rotateAgl, zii1);

            zb1 = Pus.Rodrigue(rotate, 1, rotateAgl, zb1);
            zb2 = Pus.Rodrigue(rotate, 1, rotateAgl, zb2);
            zb3 = Pus.Rodrigue(rotate, 1, rotateAgl, zb3);
            zb4 = Pus.Rodrigue(rotate, 1, rotateAgl, zb4);
            zb5 = Pus.Rodrigue(rotate, 1, rotateAgl, zb5);
            zb6 = Pus.Rodrigue(rotate, 1, rotateAgl, zb6);
            zbx = Pus.Rodrigue(rotate, 1, rotateAgl, zbx);
            zbdt1 = Pus.Rodrigue(rotate, 1, rotateAgl, zbdt1);

            zu1 = Pus.Rodrigue(rotate, 1, rotateAgl, zu1);
            zu2 = Pus.Rodrigue(rotate, 1, rotateAgl, zu2);
            zu3 = Pus.Rodrigue(rotate, 1, rotateAgl, zu3);
            zu4 = Pus.Rodrigue(rotate, 1, rotateAgl, zu4);

            //平移
            voff = new Vector3(-b * kscale - offset * 2, 0, 0);
            zi4 = Pus.OffsetXY(voff, zi4);
            zi3 = Pus.OffsetXY(voff, zi3);
            zi2 = Pus.OffsetXY(voff, zi2);
            zi1 = Pus.OffsetXY(voff, zi1);
            zdt1 = Pus.OffsetXY(voff, zdt1);
            zdt2 = Pus.OffsetXY(voff, zdt2);
            zdt3 = Pus.OffsetXY(voff, zdt3);
            zdt4 = Pus.OffsetXY(voff, zdt4);

            zii4 = Pus.OffsetXY(voff, zii4);
            zii3 = Pus.OffsetXY(voff, zii3);
            zii2 = Pus.OffsetXY(voff, zii2);
            zii1 = Pus.OffsetXY(voff, zii1);

            zb1 = Pus.OffsetXY(voff, zb1);
            zb2 = Pus.OffsetXY(voff, zb2);
            zb3 = Pus.OffsetXY(voff, zb3);
            zb4 = Pus.OffsetXY(voff, zb4);
            zb5 = Pus.OffsetXY(voff, zb5);
            zb6 = Pus.OffsetXY(voff, zb6);
            zbx = Pus.OffsetXY(voff, zbx);
            zbdt1 = Pus.OffsetXY(voff, zbdt1);

            zu1 = Pus.OffsetXY(voff, zu1);
            zu2 = Pus.OffsetXY(voff, zu2);
            zu3 = Pus.OffsetXY(voff, zu3);
            zu4 = Pus.OffsetXY(voff, zu4);

            //左视图绘制
            LwPolyline zshank = Pus.AddPointsToLwPolyLine(zii4, zb5, zb4, zb3, zdt3, zdt4, zi3);
            fun.PolyFill(dxf, zshank, lineWidth, contour);
            LwPolyline zshank2 = Pus.AddPointsToLwPolyLine(zb4, zdt4);
            fun.PolyFill(dxf, zshank2, lineWidth, contour);
            if (lambdas > 0)
            {
                LwPolyline zshank1 = Pus.AddPointsToLwPolyLine(zdt3, zdt2, zdt1, zi1);
                fun.PolyFill(dxf, zshank1, lineWidth, contour);

                LwPolyline zinsert = Pus.AddPointsToLwPolyLine(zi4, zi1, zi2, zi3);
                zinsert.IsClosed = true;
                fun.PolyFill(dxf, zinsert, lineWidth, cutting);
            }

            LwPolyline zlen1 = Pus.AddPointsToLwPolyLine(zi3, zii3, zii4, zi4);
            zlen1.IsClosed = true;
            fun.PolyFill(dxf, zlen1, lineWidth, cutting);

            if (cutagl < pi / 2)
            {
                LwPolyline zlen2 = Pus.AddPointsToLwPolyLine(zii4, zii1, zi1, zi4);
                fun.PolyFill(dxf, zlen2, lineWidth, cutting);
            }
            //if (zdt1.Y > zu4.Y)
            //{
            //    Vector2 visible = Pus.IntersOnP(zi4, zi1, zb4, zu4);
            //    LwPolyline visiLine = Pus.AddPointsToLwPolyLine(zdt1, zu4);
            //    Pus.AddPointsToLwPolyLine(visiLine, visible);
            //    fun.PolyFill(dxf, visiLine, lineWidth, contour);
            //}
            //左视图标注
            //刃倾角
            if (gamao == 0)
                Pus.NeedleDim(dxf, new Line(new Vector2(zi4.X, zi4.Y), fun.Polar(new Vector2(zi4.X, zi4.Y), Pus.AngleOnP(zi3, zi4) + pi / 180, 1)), new Line(zi3, zi4), offset * 1.5, "γo=0°", dimensionStyle);
            else
                Pus.NeedleDim(dxf, new Line(zi3, zi4), new Line(new Vector2(zi4.X, zi4.Y), fun.Polar(new Vector2(zi4.X, zi4.Y), Pus.AngleOnP(zi3, zi4) + gamao, 1)), offset * 1.5, "γo=" + Math.Round(lambdas * 180 / pi, 2) + "°", dimensionStyle);

            //LinearDimension dim_s = new LinearDimension(new Line(zi4, zii4), offset, Pus.Degree(zi4, zi3) + 90, dimensionStyle);
            //fun.dxflinedim(dxf, dim_s, s);

            //后角
            if (alphan == 0)
                Pus.NeedleDim(dxf, new Line(zi4, zii4), new Line(new Vector2(zi4.X, zi4.Y), fun.Polar(new Vector2(zi4.X, zi4.Y), Pus.AngleOnP(zi4, zii4) + pi / 180, 1)), offset + h1 * kscale, "αn=0°", dimensionStyle);
            else
                Pus.NeedleDim(dxf, new Line(zi4, zii4), new Line(new Vector2(zi4.X, zi4.Y), fun.Polar(new Vector2(zi4.X, zi4.Y), Pus.AngleOnP(zi4, zii4) + alphan, 1)), offset + h1 * kscale, "αn=" + Math.Round(alphan * 180 / pi, 2) + "°", dimensionStyle);
            //图框
            if (Convert.ToDouble(data["isframe"]) == 1)
            {
                Vector2 c4c = new Vector2((b2.X + zb3.X) / 2, (b2.Y + mu1.Y) / 2);
                Dictionary<string, Vector2> positions = Frame.frameA3X(dxf, new Vector2(c4c.X - 420 / 2, c4c.Y + 297 / 2), new Dictionary<string, object>());
                fun.writetextofC(dxf, kscale + ":1", positions["比例"], 3.5, 0, 0.6, 3);
            }

            dxf.DrawingVariables.AcadVer = DxfVersion.AutoCad2007;
            dxf.Save(path);
        }
        //J型刀头 横大
        public static void StyleJ_InsertD(Dictionary<string, Object> data)
        {

            DxfDocument dxf = new DxfDocument();
            Layer contour = new Layer("contour") { Color = AciColor.Cyan };    //1,轮廓层
            Layer cutting = new Layer("cutting") { Color = AciColor.Red };    //切削层

            string path = Convert.ToString(data["path"]);
            //参数名称取自ISO 5610-2
            double b = 8;
            double l1 = 70;
            double l2 = 25;
            double f = 10;
            double l3 = 7.75;
            double h2 = 8;
            double h1 = 8;
            double s = 2.38;
            double insertAngle = 55 * pi / 180;
            double alphan = 7 * pi / 180;
            double cutagl = 93 * pi / 180;
            double lambdas = 0;
            double gamao = 0;
            double repsilon = 0;
            #region
            try
            {
                if (data["re"] != null)
                    repsilon = Convert.ToDouble(data["re"]);
                if (repsilon <= 0)
                    repsilon = 0.01;
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["lams"] != null)
                    lambdas = Math.Abs(Convert.ToDouble(data["lams"]) * pi / 180);
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["gamo"] != null)
                    gamao = Math.Abs(Convert.ToDouble(data["gamo"]) * pi / 180);
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["b"] != null)
                    b = Convert.ToDouble(data["b"]);
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["s"] != null)
                    s = Convert.ToDouble(data["s"]);
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["lf"] != null)
                    l1 = Convert.ToDouble(data["lf"]);
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["lh"] != null)
                    l2 = Convert.ToDouble(data["lh"]);
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["wf"] != null)
                    f = Convert.ToDouble(data["wf"]);
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["h"] != null)
                    h2 = Convert.ToDouble(data["h"]);
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["hf"] != null)
                    h1 = Convert.ToDouble(data["hf"]);
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["epsr"] != null)
                    insertAngle = Convert.ToDouble(data["epsr"]) * pi / 180;
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["kapr"] != null)
                    cutagl = Convert.ToDouble(data["kapr"]) * pi / 180;
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["an"] != null)
                    alphan = Convert.ToDouble(data["an"]) * pi / 180;
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["l"] != null)
                    l3 = Convert.ToDouble(data["l"]);
            }
            catch (KeyNotFoundException) { }
            #endregion
            double kscale = 1;
            if (l1 >= 120)
                kscale = 1;
            else
                kscale = 1.5;
            double lineWidth = 1;
            //k点位置恒定
            Vector3 k = new Vector3(0, 0, 0);
            Vector3 b2 = new Vector3(k.X + l1, k.Y + f, k.Z - h1);
            Vector3 b1 = new Vector3(b2.X, b2.Y - b, b2.Z);
            Vector3 b6 = new Vector3(k.X + l2, b1.Y, b1.Z);

            //刀杆顶面
            Vector3 u1 = new Vector3(b1.X, b1.Y, b1.Z + h2);
            Vector3 u2 = new Vector3(b2.X, b2.Y, b2.Z + h2);
            Vector3 u3 = new Vector3(b6.X, b2.Y, b2.Z + h2);
            double guai = kscale;
            Vector3 u3p = new Vector3(u3.X - guai, u3.Y, u3.Z);
            Vector3 u4 = new Vector3(b6.X, b6.Y, b6.Z + h2);
            Vector3 u4p = new Vector3(u4.X - guai, u4.Y, u4.Z);

            //Kp=fun.polar(K,0,r/tan((pi-kapr)/2)-r)
            //i4=fun.polar(Kp,kapr-pi,r/tan(epsr/2)-r/tan((pi-kapr)/2))
            Vector2 kp = fun.Polar(Vector2.Zero, 0, repsilon / Math.Tan((pi - cutagl) / 2) - repsilon);
            Vector2 twoi4 = fun.Polar(kp, cutagl - pi, repsilon / Math.Tan(insertAngle / 2) - repsilon / Math.Tan((pi - cutagl) / 2));
            Vector2[] twois = Pus.DiamondPoints(twoi4, l3, insertAngle, true, cutagl);
            Vector2 twoi1 = twois[1];
            Vector2 twoi2 = twois[2];
            Vector2 twoi3 = twois[3];
            double theoffset = Math.Tan(alphan) * s;
            Vector2[] twoiis = Pus.OffsetPoints(theoffset, twois);
            Vector2 twoii4 = twoiis[0];
            Vector2 twoii3 = twoiis[3];
            Vector2 twoii1 = twoiis[1];
            Vector2 twoii2 = twoiis[2];

            //刀头面
            Vector3 i4 = new Vector3(twoi4.X, twoi4.Y, k.Z);
            Vector3 i3 = new Vector3(twoi3.X, twoi3.Y, k.Z);
            Vector3 i2 = new Vector3(twoi2.X, twoi2.Y, k.Z);
            Vector3 i1 = new Vector3(twoi1.X, twoi1.Y, k.Z);
            Vector2 cnm = Pus.IntersOnP(i1, new Vector3(i1.X + 1, i1.Y, i1.Z), u3p, u4p);
            Vector3 dt1 = new Vector3(cnm.X, cnm.Y, u4.Z);
            Vector3 dt2 = u3p;
            Vector2 xx = Pus.IntersOnP(i3, i4, u2, u3);
            Vector3 dt4 = Pus.KPoint(i3, new Vector3(xx.X, xx.Y, u3.Z), 0.7);
            Vector3 dt3 = Pus.KPoint(u3, new Vector3(xx.X, xx.Y, u3.Z), 0.85);

            Vector3 bdt1 = new Vector3(dt1.X, dt1.Y, b1.Z);
            Vector3 b5 = new Vector3(twoii4.X, twoii4.Y, b1.Z);
            Vector3 b4 = new Vector3(dt4.X, dt4.Y, b1.Z);
            Vector3 b3 = new Vector3(dt3.X, dt3.Y, b1.Z);

            Vector3 ii4 = new Vector3(twoii4.X, twoii4.Y, k.Z - s);
            Vector3 ii3 = new Vector3(twoii3.X, twoii3.Y, k.Z - s);
            Vector3 ii1 = new Vector3(twoii1.X, twoii1.Y, k.Z - s);
            Vector3 ii2 = new Vector3(twoii2.X, twoii2.Y, k.Z - s);

            i4 = Pus.LinearTrans(kscale, i4);
            i3 = Pus.LinearTrans(kscale, i3);
            i2 = Pus.LinearTrans(kscale, i2);
            i1 = Pus.LinearTrans(kscale, i1);
            dt1 = Pus.LinearTrans(kscale, dt1);
            dt2 = Pus.LinearTrans(kscale, dt2);
            dt3 = Pus.LinearTrans(kscale, dt3);
            dt4 = Pus.LinearTrans(kscale, dt4);

            ii4 = Pus.LinearTrans(kscale, ii4);
            ii3 = Pus.LinearTrans(kscale, ii3);
            ii2 = Pus.LinearTrans(kscale, ii2);
            ii1 = Pus.LinearTrans(kscale, ii1);

            b1 = Pus.LinearTrans(kscale, b1);
            b2 = Pus.LinearTrans(kscale, b2);
            b3 = Pus.LinearTrans(kscale, b3);
            b4 = Pus.LinearTrans(kscale, b4);
            b5 = Pus.LinearTrans(kscale, b5);
            b6 = Pus.LinearTrans(kscale, b6);
            bdt1 = Pus.LinearTrans(kscale, bdt1);

            u1 = Pus.LinearTrans(kscale, u1);
            u2 = Pus.LinearTrans(kscale, u2);
            u3 = Pus.LinearTrans(kscale, u3);
            u3p = Pus.LinearTrans(kscale, u3p);
            u4 = Pus.LinearTrans(kscale, u4);


            //主视图
            LwPolyline mshank = Pus.AddPointsToLwPolyLine(u1, u2, u3, u4);
            mshank.IsClosed = true;
            fun.PolyFill(dxf, mshank, lineWidth, contour);

            LwPolyline minsert = Pus.AddPointsToLwPolyLine(i4, i1, i2, i3);
            minsert.IsClosed = true;
            Pus.AglToArc(minsert, repsilon);

            LwPolyline mhead = Pus.AddPointsToLwPolyLine(i3, i2, i1, dt1, dt2, dt3, dt4, i3);
            mhead.IsClosed = true;
            fun.PolyFill(dxf, mhead, lineWidth, contour);
            LwPolyline mheadc1 = Pus.AddPointsToLwPolyLine(dt1, u4);
            fun.PolyFill(dxf, mheadc1, lineWidth, contour);
            LwPolyline mheadc2 = Pus.AddPointsToLwPolyLine(dt2, u3);
            fun.PolyFill(dxf, mheadc2, lineWidth, contour);

            fun.PolyFill(dxf, minsert, lineWidth, cutting);
            //m视图标注
            DimensionStyle dimensionStyle = new DimensionStyle("mystyle");
            dimensionStyle.ArrowSize = kscale * 1.2;
            dimensionStyle.DimArrow1 = DimensionArrowhead.Closedfilled;
            dimensionStyle.DimArrow2 = DimensionArrowhead.Closedfilled;
            dimensionStyle.TextHeight = kscale;
            dimensionStyle.TextOffset = kscale / 2;
            double offset = 7 * kscale;
            LinearDimension dim_f = new LinearDimension(new Line(new Vector2(k.X, k.Y), new Vector2(b3.X, b3.Y)), offset * 1.5, Pus.Degree(b1, b2), dimensionStyle);
            fun.dxflinedim(dxf, dim_f, f);
            LinearDimension dim_l1 = new LinearDimension(new Line(new Vector2(k.X, k.Y), new Vector2(b1.X, b1.Y)), offset * 1.5, Pus.Degree(new Vector2(b1.X, b1.Y), new Vector2(b6.X, b6.Y)), dimensionStyle);
            fun.dxflinedim(dxf, dim_l1, l1);
            LinearDimension dim_l2 = new LinearDimension(new Line(new Vector2(k.X, k.Y), new Vector2(u4.X, u4.Y)), offset, Pus.Degree(new Vector2(u1.X, u1.Y), new Vector2(u4.X, u4.Y)), dimensionStyle);
            fun.dxflinedim(dxf, dim_l2, l2);
            //LinearDimension dim_l3 = new LinearDimension(new Line(i2, i3), offset, Pus.Degree(new Vector2(i3.X, i3.Y), new Vector2(i2.X, i2.Y)), dimensionStyle);
            //fun.dxflinedim(dxf, dim_l3, Math.Round(l3, 2));
            LinearDimension dim_b = new LinearDimension(new Line(new Vector2(u1.X, u1.Y), new Vector2(u2.X, u2.Y)), offset, Pus.Degree(new Vector2(u2.X, u2.Y), new Vector2(u1.X, u1.Y)), dimensionStyle);
            fun.dxflinedim(dxf, dim_b, b);
            //Angular2LineDimension dim_insertAgl = new Angular2LineDimension(new Line(i4, i3), new Line(i4, i1), offset * 0.5, dimensionStyle);
            //dim_insertAgl.UserText = Math.Round(insertAngle * 180 / pi, 2) + "°";
            //dxf.AddEntity(dim_insertAgl);
            Angular2LineDimension dim_cutagl = new Angular2LineDimension(new Line(i4, i1), new Line(new Vector2(i4.X, i4.Y), fun.Polar(new Vector2(i4.X, i4.Y), -pi / 2, 1)), offset * 0.4, dimensionStyle);
            dim_cutagl.UserText = Math.Round(cutagl * 180 / pi, 2) + "°";
            dxf.AddEntity(dim_cutagl);
            //RadialDimension dim_repsilon = new RadialDimension(Pus.GetArcFromPline(minsert, 1), Pus.Degree(i3, i4) - 10, offset * 0.5, dimensionStyle);
            //dim_repsilon.UserText = "rε=" + repsilon;
            //dxf.AddEntity(dim_repsilon);
            //放倒(所有点)尚未平移到下方，因为只能绕着原点k所在轴旋转
            Vector3 rotate = new Vector3(-1, 0, 0);
            double rotateAgl = pi / 2;
            i4 = Pus.Rodrigue(rotate, 1, rotateAgl, i4);
            i3 = Pus.Rodrigue(rotate, 1, rotateAgl, i3);
            i2 = Pus.Rodrigue(rotate, 1, rotateAgl, i2);
            i1 = Pus.Rodrigue(rotate, 1, rotateAgl, i1);
            dt1 = Pus.Rodrigue(rotate, 1, rotateAgl, dt1);
            dt2 = Pus.Rodrigue(rotate, 1, rotateAgl, dt2);
            dt3 = Pus.Rodrigue(rotate, 1, rotateAgl, dt3);
            dt4 = Pus.Rodrigue(rotate, 1, rotateAgl, dt4);
            ii4 = Pus.Rodrigue(rotate, 1, rotateAgl, ii4);
            ii3 = Pus.Rodrigue(rotate, 1, rotateAgl, ii3);
            ii2 = Pus.Rodrigue(rotate, 1, rotateAgl, ii2);
            ii1 = Pus.Rodrigue(rotate, 1, rotateAgl, ii1);

            b1 = Pus.Rodrigue(rotate, 1, rotateAgl, b1);
            b2 = Pus.Rodrigue(rotate, 1, rotateAgl, b2);
            b3 = Pus.Rodrigue(rotate, 1, rotateAgl, b3);
            b4 = Pus.Rodrigue(rotate, 1, rotateAgl, b4);
            b5 = Pus.Rodrigue(rotate, 1, rotateAgl, b5);
            b6 = Pus.Rodrigue(rotate, 1, rotateAgl, b6);
            bdt1 = Pus.Rodrigue(rotate, 1, rotateAgl, bdt1);

            u1 = Pus.Rodrigue(rotate, 1, rotateAgl, u1);
            u2 = Pus.Rodrigue(rotate, 1, rotateAgl, u2);
            u3 = Pus.Rodrigue(rotate, 1, rotateAgl, u3);
            u3p = Pus.Rodrigue(rotate, 1, rotateAgl, u3p);
            u4 = Pus.Rodrigue(rotate, 1, rotateAgl, u4);

            //创建lambds
            rotate = new Vector3(Math.Sin(cutagl - pi / 2), k.Z, Math.Cos(cutagl - pi / 2));
            rotateAgl = lambdas;
            i4 = Pus.Rodrigue(rotate, 1, rotateAgl, i4);
            i3 = Pus.Rodrigue(rotate, 1, rotateAgl, i3);
            i2 = Pus.Rodrigue(rotate, 1, rotateAgl, i2);
            i1 = Pus.Rodrigue(rotate, 1, rotateAgl, i1);
            ii4 = Pus.Rodrigue(rotate, 1, rotateAgl, ii4);
            ii3 = Pus.Rodrigue(rotate, 1, rotateAgl, ii3);
            ii2 = Pus.Rodrigue(rotate, 1, rotateAgl, ii2);
            ii1 = Pus.Rodrigue(rotate, 1, rotateAgl, ii1);
            dt1 = Pus.Rodrigue(rotate, 1, rotateAgl, dt1);
            dt2 = Pus.Rodrigue(rotate, 1, rotateAgl, dt2);
            dt3 = Pus.Rodrigue(rotate, 1, rotateAgl, dt3);
            dt4 = Pus.Rodrigue(rotate, 1, rotateAgl, dt4);

            //创建gamo
            double disi1_i4 = Vector3.Distance(i1, i4);
            rotate = (i1 - i4) / disi1_i4;
            rotateAgl = gamao;
            i4 = Pus.Rodrigue(rotate, 1, rotateAgl, i4);
            i3 = Pus.Rodrigue(rotate, 1, rotateAgl, i3);
            i2 = Pus.Rodrigue(rotate, 1, rotateAgl, i2);
            i1 = Pus.Rodrigue(rotate, 1, rotateAgl, i1);
            ii4 = Pus.Rodrigue(rotate, 1, rotateAgl, ii4);
            ii3 = Pus.Rodrigue(rotate, 1, rotateAgl, ii3);
            ii2 = Pus.Rodrigue(rotate, 1, rotateAgl, ii2);
            ii1 = Pus.Rodrigue(rotate, 1, rotateAgl, ii1);
            dt1 = Pus.Rodrigue(rotate, 1, rotateAgl, dt1);
            dt2 = Pus.Rodrigue(rotate, 1, rotateAgl, dt2);
            dt3 = Pus.Rodrigue(rotate, 1, rotateAgl, dt3);
            dt4 = Pus.Rodrigue(rotate, 1, rotateAgl, dt4);

            //重新计算刀头的点
            Face3d face4dt = new Face3d(dt2, dt3, dt4);
            Vector3 v4dt = u2 - b2;
            dt1 = Pus.Inters(face4dt, new Line(bdt1, bdt1 + v4dt));
            dt2 = Pus.Inters(face4dt, new Line(u3p, u3p + v4dt));
            dt3 = Pus.Inters(face4dt, new Line(b3, b3 + v4dt));
            dt4 = Pus.Inters(face4dt, new Line(b4, b4 + v4dt));

            Face3d face4buttom = new Face3d(b1, b2, b3);
            b5 = Pus.Inters(face4buttom, new Line(ii4, ii4 + v4dt));
            Vector3 bx = Pus.Inters(face4buttom, new Line(ii1, ii1 + v4dt));
            bdt1 = Pus.Inters(face4buttom, new Line(dt1, dt1 + v4dt));

            //平移所有点到下方
            Vector3 voff = new Vector3(0, -b * kscale - offset * 1.5, 0);
            Vector3 mk = Pus.OffsetXY(voff, k);
            Vector3 mi4 = Pus.OffsetXY(voff, i4);
            Vector3 mi3 = Pus.OffsetXY(voff, i3);
            Vector3 mi2 = Pus.OffsetXY(voff, i2);
            Vector3 mi1 = Pus.OffsetXY(voff, i1);
            Vector3 mdt1 = Pus.OffsetXY(voff, dt1);
            Vector3 mdt2 = Pus.OffsetXY(voff, dt2);
            Vector3 mdt3 = Pus.OffsetXY(voff, dt3);
            Vector3 mdt4 = Pus.OffsetXY(voff, dt4);
            Vector3 mii4 = Pus.OffsetXY(voff, ii4);
            Vector3 mii3 = Pus.OffsetXY(voff, ii3);
            Vector3 mii2 = Pus.OffsetXY(voff, ii2);
            Vector3 mii1 = Pus.OffsetXY(voff, ii1);

            Vector3 mb1 = Pus.OffsetXY(voff, b1);
            Vector3 mb2 = Pus.OffsetXY(voff, b2);
            Vector3 mb3 = Pus.OffsetXY(voff, b3);
            Vector3 mb4 = Pus.OffsetXY(voff, b4);
            Vector3 mb5 = Pus.OffsetXY(voff, b5);
            Vector3 mb6 = Pus.OffsetXY(voff, b6);
            Vector3 mbx = Pus.OffsetXY(voff, bx);
            Vector3 mbdt1 = Pus.OffsetXY(voff, bdt1);

            Vector3 mu1 = Pus.OffsetXY(voff, u1);
            Vector3 mu2 = Pus.OffsetXY(voff, u2);
            Vector3 mu3 = Pus.OffsetXY(voff, u3);
            Vector3 mu4 = Pus.OffsetXY(voff, u4);

            LwPolyline lshank = Pus.AddPointsToLwPolyLine(mb1, mu1, mu4, mb6);
            lshank.IsClosed = true;
            fun.PolyFill(dxf, lshank, lineWidth, contour);
            LwPolyline lshank_dt = Pus.AddPointsToLwPolyLine(mdt1, mu4);
            fun.PolyFill(dxf, lshank_dt, lineWidth, contour);
            LwPolyline lshank_dt1 = Pus.AddPointsToLwPolyLine(mdt2, mu3);
            fun.PolyFill(dxf, lshank_dt1, lineWidth, contour);

            LwPolyline lhead = Pus.AddPointsToLwPolyLine(mii4, mb5, mbdt1, mdt1);
            fun.PolyFill(dxf, lhead, lineWidth, contour);
            LwPolyline lhead1 = Pus.AddPointsToLwPolyLine(mbdt1, mb6);
            fun.PolyFill(dxf, lhead1, lineWidth, contour);
            LwPolyline lhead2 = Pus.AddPointsToLwPolyLine(mdt1, mi1);
            fun.PolyFill(dxf, lhead2, lineWidth, contour);
            LwPolyline lhead3 = Pus.AddPointsToLwPolyLine(mdt1, mbdt1);
            fun.PolyFill(dxf, lhead3, lineWidth, contour);
            LwPolyline lhead4 = Pus.AddPointsToLwPolyLine(mbx, mii1);
            fun.PolyFill(dxf, lhead4, lineWidth, contour);
            if (gamao > 0)
            {
                LwPolyline lheadu = Pus.AddPointsToLwPolyLine(mi1, mdt1, mdt2, mdt3, mdt4, mi3);
                fun.PolyFill(dxf, lheadu, lineWidth, contour);

                LwPolyline linsertu = Pus.AddPointsToLwPolyLine(mi4, mi1, mi2, mi3);
                linsertu.IsClosed = true;
                fun.PolyFill(dxf, linsertu, lineWidth, cutting);
            }

            LwPolyline linsertf = Pus.AddPointsToLwPolyLine(mi4, mii4, mii1, mi1);
            linsertf.IsClosed = true;
            fun.PolyFill(dxf, linsertf, lineWidth, cutting);
            //l视图标注
            LinearDimension dim_h1 = new LinearDimension(new Line(new Vector2(mk.X, mk.Y), new Vector2(mb5.X, mb5.Y)), offset * 0.5, Pus.Degree(b1, u1), dimensionStyle);
            fun.dxflinedim(dxf, dim_h1, h1);
            LinearDimension dim_h2 = new LinearDimension(new Line(new Vector2(mu1.X, mu1.Y), new Vector2(mb1.X, mb1.Y)), offset, Pus.Degree(u1, b1), dimensionStyle);
            fun.dxflinedim(dxf, dim_h2, h2);
            if (lambdas == 0)
                Pus.NeedleDim(dxf, new Line(new Vector2(mi4.X, mi4.Y), fun.Polar(new Vector2(mi4.X, mi4.Y), pi / 180, 1)), new Line(mi4, mi4 + mu4 - mu2), kscale * offset, "λs=0°", dimensionStyle);
            else
                Pus.NeedleDim(dxf, new Line(mi4, mi1), new Line(mi4, mi4 + mu4 - mu2), kscale * offset, "λs=" + Math.Round(lambdas * 180 / pi, 2) + "°", dimensionStyle);
            //左视图
            //所有点移动到原点
            //立正
            rotate = new Vector3(1, 0, 0);
            rotateAgl = pi / 2;
            Vector3 zi4 = Pus.Rodrigue(rotate, 1, rotateAgl, i4);
            Vector3 zi3 = Pus.Rodrigue(rotate, 1, rotateAgl, i3);
            Vector3 zi2 = Pus.Rodrigue(rotate, 1, rotateAgl, i2);
            Vector3 zi1 = Pus.Rodrigue(rotate, 1, rotateAgl, i1);
            Vector3 zdt1 = Pus.Rodrigue(rotate, 1, rotateAgl, dt1);
            Vector3 zdt2 = Pus.Rodrigue(rotate, 1, rotateAgl, dt2);
            Vector3 zdt3 = Pus.Rodrigue(rotate, 1, rotateAgl, dt3);
            Vector3 zdt4 = Pus.Rodrigue(rotate, 1, rotateAgl, dt4);

            Vector3 zii4 = Pus.Rodrigue(rotate, 1, rotateAgl, ii4);
            Vector3 zii3 = Pus.Rodrigue(rotate, 1, rotateAgl, ii3);
            Vector3 zii2 = Pus.Rodrigue(rotate, 1, rotateAgl, ii2);
            Vector3 zii1 = Pus.Rodrigue(rotate, 1, rotateAgl, ii1);

            Vector3 zb1 = Pus.Rodrigue(rotate, 1, rotateAgl, b1);
            Vector3 zb2 = Pus.Rodrigue(rotate, 1, rotateAgl, b2);
            Vector3 zb3 = Pus.Rodrigue(rotate, 1, rotateAgl, b3);
            Vector3 zb4 = Pus.Rodrigue(rotate, 1, rotateAgl, b4);
            Vector3 zb5 = Pus.Rodrigue(rotate, 1, rotateAgl, b5);
            Vector3 zb6 = Pus.Rodrigue(rotate, 1, rotateAgl, b6);
            Vector3 zbx = Pus.Rodrigue(rotate, 1, rotateAgl, bx);
            Vector3 zbdt1 = Pus.Rodrigue(rotate, 1, rotateAgl, bdt1);

            Vector3 zu1 = Pus.Rodrigue(rotate, 1, rotateAgl, u1);
            Vector3 zu2 = Pus.Rodrigue(rotate, 1, rotateAgl, u2);
            Vector3 zu3 = Pus.Rodrigue(rotate, 1, rotateAgl, u3);
            Vector3 zu4 = Pus.Rodrigue(rotate, 1, rotateAgl, u4);

            //绕y转，露出左面
            rotate = new Vector3(0, 1, 0);
            rotateAgl = pi / 2;
            zi4 = Pus.Rodrigue(rotate, 1, rotateAgl, zi4);
            zi3 = Pus.Rodrigue(rotate, 1, rotateAgl, zi3);
            zi2 = Pus.Rodrigue(rotate, 1, rotateAgl, zi2);
            zi1 = Pus.Rodrigue(rotate, 1, rotateAgl, zi1);
            zdt1 = Pus.Rodrigue(rotate, 1, rotateAgl, zdt1);
            zdt2 = Pus.Rodrigue(rotate, 1, rotateAgl, zdt2);
            zdt3 = Pus.Rodrigue(rotate, 1, rotateAgl, zdt3);
            zdt4 = Pus.Rodrigue(rotate, 1, rotateAgl, zdt4);

            zii4 = Pus.Rodrigue(rotate, 1, rotateAgl, zii4);
            zii3 = Pus.Rodrigue(rotate, 1, rotateAgl, zii3);
            zii2 = Pus.Rodrigue(rotate, 1, rotateAgl, zii2);
            zii1 = Pus.Rodrigue(rotate, 1, rotateAgl, zii1);

            zb1 = Pus.Rodrigue(rotate, 1, rotateAgl, zb1);
            zb2 = Pus.Rodrigue(rotate, 1, rotateAgl, zb2);
            zb3 = Pus.Rodrigue(rotate, 1, rotateAgl, zb3);
            zb4 = Pus.Rodrigue(rotate, 1, rotateAgl, zb4);
            zb5 = Pus.Rodrigue(rotate, 1, rotateAgl, zb5);
            zb6 = Pus.Rodrigue(rotate, 1, rotateAgl, zb6);
            zbx = Pus.Rodrigue(rotate, 1, rotateAgl, zbx);
            zbdt1 = Pus.Rodrigue(rotate, 1, rotateAgl, zbdt1);

            zu1 = Pus.Rodrigue(rotate, 1, rotateAgl, zu1);
            zu2 = Pus.Rodrigue(rotate, 1, rotateAgl, zu2);
            zu3 = Pus.Rodrigue(rotate, 1, rotateAgl, zu3);
            zu4 = Pus.Rodrigue(rotate, 1, rotateAgl, zu4);

            //平移
            voff = new Vector3(-b * kscale - offset * 2, 0, 0);
            zi4 = Pus.OffsetXY(voff, zi4);
            zi3 = Pus.OffsetXY(voff, zi3);
            zi2 = Pus.OffsetXY(voff, zi2);
            zi1 = Pus.OffsetXY(voff, zi1);
            zdt1 = Pus.OffsetXY(voff, zdt1);
            zdt2 = Pus.OffsetXY(voff, zdt2);
            zdt3 = Pus.OffsetXY(voff, zdt3);
            zdt4 = Pus.OffsetXY(voff, zdt4);

            zii4 = Pus.OffsetXY(voff, zii4);
            zii3 = Pus.OffsetXY(voff, zii3);
            zii2 = Pus.OffsetXY(voff, zii2);
            zii1 = Pus.OffsetXY(voff, zii1);

            zb1 = Pus.OffsetXY(voff, zb1);
            zb2 = Pus.OffsetXY(voff, zb2);
            zb3 = Pus.OffsetXY(voff, zb3);
            zb4 = Pus.OffsetXY(voff, zb4);
            zb5 = Pus.OffsetXY(voff, zb5);
            zb6 = Pus.OffsetXY(voff, zb6);
            zbx = Pus.OffsetXY(voff, zbx);
            zbdt1 = Pus.OffsetXY(voff, zbdt1);

            zu1 = Pus.OffsetXY(voff, zu1);
            zu2 = Pus.OffsetXY(voff, zu2);
            zu3 = Pus.OffsetXY(voff, zu3);
            zu4 = Pus.OffsetXY(voff, zu4);

            //左视图绘制
            LwPolyline zshank = Pus.AddPointsToLwPolyLine(zii4, zb5, zb4, zb3, zdt3, zdt4, zi3);
            fun.PolyFill(dxf, zshank, lineWidth, contour);
            LwPolyline zshank2 = Pus.AddPointsToLwPolyLine(zb4, zdt4);
            fun.PolyFill(dxf, zshank2, lineWidth, contour);
            if (lambdas > 0)
            {
                LwPolyline zshank1 = Pus.AddPointsToLwPolyLine(zdt3, zdt2, zdt1, zi1);
                fun.PolyFill(dxf, zshank1, lineWidth, contour);

                LwPolyline zinsert = Pus.AddPointsToLwPolyLine(zi4, zi1, zi2, zi3);
                zinsert.IsClosed = true;
                fun.PolyFill(dxf, zinsert, lineWidth, cutting);
            }

            LwPolyline zlen1 = Pus.AddPointsToLwPolyLine(zi3, zii3, zii4, zi4);
            zlen1.IsClosed = true;
            fun.PolyFill(dxf, zlen1, lineWidth, cutting);

            if (cutagl < pi / 2)
            {
                LwPolyline zlen2 = Pus.AddPointsToLwPolyLine(zii4, zii1, zi1, zi4);
                fun.PolyFill(dxf, zlen2, lineWidth, cutting);
            }
            //if (zdt1.Y > zu4.Y)
            //{
            //    Vector2 visible = Pus.IntersOnP(zi4, zi1, zb4, zu4);
            //    LwPolyline visiLine = Pus.AddPointsToLwPolyLine(zdt1, zu4);
            //    Pus.AddPointsToLwPolyLine(visiLine, visible);
            //    fun.PolyFill(dxf, visiLine, lineWidth, contour);
            //}
            //左视图标注
            //刃倾角
            if (gamao == 0)
                Pus.NeedleDim(dxf, new Line(new Vector2(zi4.X, zi4.Y), fun.Polar(new Vector2(zi4.X, zi4.Y), Pus.AngleOnP(zi3, zi4) + pi / 180, 1)), new Line(zi3, zi4), offset * 1.5, "γo=0°", dimensionStyle);
            else
                Pus.NeedleDim(dxf, new Line(zi3, zi4), new Line(new Vector2(zi4.X, zi4.Y), fun.Polar(new Vector2(zi4.X, zi4.Y), Pus.AngleOnP(zi3, zi4) + gamao, 1)), offset * 1.5, "γo=" + Math.Round(lambdas * 180 / pi, 2) + "°", dimensionStyle);

            //LinearDimension dim_s = new LinearDimension(new Line(zi4, zii4), offset, Pus.Degree(zi4, zi3) + 90, dimensionStyle);
            //fun.dxflinedim(dxf, dim_s, s);

            //后角
            if (alphan == 0)
                Pus.NeedleDim(dxf, new Line(zi4, zii4), new Line(new Vector2(zi4.X, zi4.Y), fun.Polar(new Vector2(zi4.X, zi4.Y), Pus.AngleOnP(zi4, zii4) + pi / 180, 1)), offset + h1 * kscale, "αn=0°", dimensionStyle);
            else
                Pus.NeedleDim(dxf, new Line(zi4, zii4), new Line(new Vector2(zi4.X, zi4.Y), fun.Polar(new Vector2(zi4.X, zi4.Y), Pus.AngleOnP(zi4, zii4) + alphan, 1)), offset + h1 * kscale, "αn=" + Math.Round(alphan * 180 / pi, 2) + "°", dimensionStyle);
            //图框
            if (Convert.ToDouble(data["isframe"]) == 1)
            {
                Vector2 c4c = new Vector2((b2.X + zb3.X) / 2, (b2.Y + mu1.Y) / 2);
                Dictionary<string, Vector2> positions = Frame.frameA3X(dxf, new Vector2(c4c.X - 420 / 2, c4c.Y + 297 / 2), new Dictionary<string, object>());
                fun.writetextofC(dxf, kscale + ":1", positions["比例"], 3.5, 0, 0.6, 3);
            }

            dxf.DrawingVariables.AcadVer = DxfVersion.AutoCad2007;
            dxf.Save(path);
        }
        public static void StyleJ_InsertT(Dictionary<string, Object> data)
        {

            DxfDocument dxf = new DxfDocument();
            Layer contour = new Layer("contour") { Color = AciColor.Cyan };    //1,轮廓层
            Layer cutting = new Layer("cutting") { Color = AciColor.Red };    //切削层

            string path = Convert.ToString(data["path"]);
            //参数名称取自ISO 5610-2
            double b = 20;
            double l1 = 100;
            double l2 = 32;
            double f = 25;
            double l3 = 16.5;
            double h2 = 20;
            double h1 = 20;
            double s = 3.97;
            double insertAngle = pi / 3;
            double alphan = 7 * pi / 180;
            double cutagl = 93 * pi / 180;
            double lambdas = 0;
            double gammao = 0;
            double repsilon = 0;
            #region
            try
            {
                if (data["re"] != null)
                    repsilon = Convert.ToDouble(data["re"]);
                if (repsilon <= 0)
                    repsilon = 0.01;
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["lams"] != null)
                    lambdas = Convert.ToDouble(data["lams"]) * pi / 180;
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["gamo"] != null)
                    gammao = Convert.ToDouble(data["gamo"]) * pi / 180;
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["b"] != null)
                    b = Convert.ToDouble(data["b"]);
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["s"] != null)
                    s = Convert.ToDouble(data["s"]);
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["lf"] != null)
                    l1 = Convert.ToDouble(data["lf"]);
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["lh"] != null)
                    l2 = Convert.ToDouble(data["lh"]);
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["wf"] != null)
                    f = Convert.ToDouble(data["wf"]);
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["h"] != null)
                    h2 = Convert.ToDouble(data["h"]);
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["hf"] != null)
                    h1 = Convert.ToDouble(data["hf"]);
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["epsr"] != null)
                    insertAngle = Convert.ToDouble(data["epsr"]) * pi / 180;
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["kapr"] != null)
                    cutagl = Convert.ToDouble(data["kapr"]) * pi / 180;
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["an"] != null)
                    alphan = Convert.ToDouble(data["an"]) * pi / 180;
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["ic"] != null)
                    l3 = Pus.GetLByTIC(Convert.ToDouble(data["ic"]));
            }
            catch (KeyNotFoundException) { }
            #endregion
            double kscale = 1;
            if (l1 >= 120)
                kscale = 1;
            else
                kscale = 1.5;
            double lineWidth = 1;
            //k点位置恒定
            Vector3 k = new Vector3(0, 0, 0);
            RectShank rs = new RectShank(b, l1, f, l2, l3, 3, true, insertAngle, cutagl, lambdas, true, gammao, alphan, s, repsilon);
            Vector3[] shank = rs.Shank;
            Vector3[] inserts = rs.Inserts;
            //线性变换
            double theta = 0 * pi / 180;
            Matrix3 linearTrans = new Matrix3(
                Math.Cos(theta) * kscale, -Math.Sin(theta) * kscale, 0,
                Math.Sin(theta) * kscale, Math.Cos(theta) * kscale, 0,
                              0, 0, kscale
            );
            for (int i = 0; i < shank.Length; i++)
            {
                shank[i] = linearTrans * shank[i];
            }
            for (int i = 0; i < inserts.Length; i++)
            {
                inserts[i] = linearTrans * inserts[i];
            }
            repsilon *= kscale;

            Vector3[] head = new Vector3[9];
            Face3d fb = new Face3d(shank[0], shank[1], shank[2]);
            Face3d fbk = new Face3d(shank[1], shank[2], shank[6]);
            Face3d fiu = new Face3d(inserts[3], inserts[4], inserts[5]);
            Vector3 nbu = Pus.UnitVector(shank[0], shank[4]);
            head[0] = Pus.Inters(fb, inserts[0], inserts[0] + nbu);
            Face3d fd0 = new Face3d(inserts[0], inserts[1], head[0]);
            Face3d fd1 = new Face3d(inserts[0], head[0], inserts[2]);
            Face3d fc0 = new Face3d(Pus.ReferenceV3(shank[3], -kscale, 0, 0), Pus.ReferenceV3(shank[2], -kscale, 0, 0), Pus.ReferenceV3(shank[6], -kscale, 0, 0));
            Face3d fc1 = new Face3d(Pus.ReferenceV3(shank[3], -1.5 * kscale, 0, 0), Pus.ReferenceV3(shank[2], -1.5 * kscale, 0, 0), Pus.ReferenceV3(shank[6], -1.5 * kscale, 0, 0));
            head[1] = Pus.Inters(fc1, Pus.Inters(fd0, fb, head[0]));
            head[2] = Pus.Inters(fbk, Pus.Inters(fd1, fb, head[0]));
            head[3] = Pus.Inters(fd0, inserts[4], inserts[5]);
            head[4] = Pus.Inters(fc1, Pus.Inters(fiu, fd0, head[3]));
            Face3d fcq = new Face3d(shank[3], shank[7], head[4]);
            head[5] = Pus.Inters(fc0, Pus.Inters(fiu, fcq, head[4]));
            head[6] = Pus.Inters(fbk, Pus.Inters(fiu, fc0, head[5]));
            head[7] = Pus.Inters(fd1, Pus.Inters(fbk, fiu, head[6]));
            head[8] = Pus.Inters(fd1, inserts[4], inserts[5]);

            //mview
            LwPolyline msk = Pus.AddPointsToLwPolyLine(shank[4], shank[5], shank[6], shank[7]);
            msk.IsClosed = true;
            fun.PolyFill(dxf, msk, lineWidth, contour);

            LwPolyline mfiu = Pus.AddPointsToLwPolyLine(head[3], head[4], head[5], head[6], head[7], head[8]);
            mfiu.IsClosed = true;
            fun.PolyFill(dxf, mfiu, lineWidth, contour);
            LwPolyline mfcu = Pus.AddPointsToLwPolyLine(shank[7], shank[6], head[6], head[5]);
            mfcu.IsClosed = true;
            fun.PolyFill(dxf, mfcu, lineWidth, contour);

            LwPolyline mist = Pus.AddPointsToLwPolyLine(inserts[3], inserts[4], inserts[5]);
            mist.IsClosed = true;
            Pus.AglToArc(mist, repsilon);
            fun.PolyFill(dxf, mist, lineWidth, cutting);
            //mview标注
            DimensionStyle dimensionStyle = new DimensionStyle("mystyle");
            dimensionStyle.ArrowSize = kscale * 1.5;
            dimensionStyle.DimArrow1 = DimensionArrowhead.Closedfilled;
            dimensionStyle.DimArrow2 = DimensionArrowhead.Closedfilled;
            dimensionStyle.TextHeight = kscale * 1.5;
            dimensionStyle.TextOffset = kscale;
            double offset = 7 * kscale;
            LinearDimension dim_b = new LinearDimension(new Line(shank[5], shank[4]), offset, Pus.Degree(shank[5], shank[4]), dimensionStyle);
            fun.dxflinedim(dxf, dim_b, b);
            LinearDimension dim_f = new LinearDimension(new Line(Vector3.Zero, head[7]), head[7].X / 2 + offset, Pus.Degree(shank[4], shank[5]), dimensionStyle);
            fun.dxflinedim(dxf, dim_f, f);
            LinearDimension dim_l1 = new LinearDimension(new Line(Vector3.Zero, shank[4]), b / 2 * kscale, 180, dimensionStyle);
            fun.dxflinedim(dxf, dim_l1, l1);
            LinearDimension dim_l2 = new LinearDimension(new Line(shank[6], Vector3.Zero), shank[6].Y / 2 + offset, 0, dimensionStyle);
            fun.dxflinedim(dxf, dim_l2, l2);
            Angular2LineDimension dim_cutagl = new Angular2LineDimension(new Line(inserts[3], inserts[4]),
                new Line(Pus.ToV2(inserts[3]), fun.Polar(Pus.ToV2(inserts[3]), -pi / 2, 1)), offset, dimensionStyle);
            dim_cutagl.UserText = Math.Round(cutagl * 180 / pi, 1) + "°";
            dxf.AddEntity(dim_cutagl);

            //zview
            //绕y轴旋转pi/2再平移得到左视图
            Vector3[] zshank = new Vector3[shank.Length];
            Vector3[] zhead = new Vector3[head.Length];
            Vector3[] zinserts = new Vector3[inserts.Length];
            Vector3 zviewMkr = new Vector3(0, 1, 0);
            double yR = pi / 2;
            double zoffset = -2 * b * kscale;
            for (int i = 0; i < shank.Length; i++)
            {
                zshank[i] = Pus.Rodrigue(zviewMkr, 1, yR, shank[i]);
                zshank[i].X += zoffset;
            }
            for (int i = 0; i < inserts.Length; i++)
            {
                zinserts[i] = Pus.Rodrigue(zviewMkr, 1, yR, inserts[i]);
                zinserts[i].X += zoffset;
            }
            for (int i = 0; i < head.Length; i++)
            {
                zhead[i] = Pus.Rodrigue(zviewMkr, 1, yR, head[i]);
                zhead[i].X += zoffset;
            }
            Vector3 zk = k;
            zk.X += zoffset;

            LwPolyline zfd1 = Pus.AddPointsToLwPolyLine(zinserts[0], zhead[0], zhead[2], zhead[7], zhead[8]);
            fun.PolyFill(dxf, zfd1, lineWidth, contour);

            LwPolyline zist = Pus.AddPointsToLwPolyLine(zinserts[0], zinserts[3], zinserts[5], zinserts[2]);
            zist.IsClosed = true;
            fun.PolyFill(dxf, zist, lineWidth, cutting);

            if (zinserts[4].X > zinserts[3].X)
            {
                LwPolyline zfiu = Pus.AddPointsToLwPolyLine(zhead[3], zhead[4], zhead[5], zhead[6], zhead[7], zhead[8]);
                fun.PolyFill(dxf, zfiu, lineWidth, contour);

                LwPolyline zistu = Pus.AddPointsToLwPolyLine(zinserts[3], zinserts[4], zinserts[5]);
                zistu.IsClosed = true;
                fun.PolyFill(dxf, zistu, lineWidth, cutting);
            }


            //lview
            Vector3[] lshank = new Vector3[shank.Length];
            Vector3[] linserts = new Vector3[inserts.Length];
            Vector3[] lhead = new Vector3[head.Length];
            //放倒
            Vector3 laydown = new Vector3(-1, 0, 0);
            double laydownR = pi / 2;
            double loffset = -h2 * 2 * kscale;
            for (int i = 0; i < shank.Length; i++)
            {
                lshank[i] = Pus.Rodrigue(laydown, 1, laydownR, shank[i]);
                lshank[i].Y += loffset;
            }

            for (int i = 0; i < inserts.Length; i++)
            {
                linserts[i] = Pus.Rodrigue(laydown, 1, laydownR, inserts[i]);
                linserts[i].Y += loffset;
            }

            for (int i = 0; i < head.Length; i++)
            {
                lhead[i] = Pus.Rodrigue(laydown, 1, laydownR, head[i]);
                lhead[i].Y += loffset;
            }
            Vector3 lk = k;
            lk.Y += loffset;

            LwPolyline lsk = Pus.AddPointsToLwPolyLine(lshank[0], lshank[4], lshank[7], lshank[3]);
            lsk.IsClosed = true;
            fun.PolyFill(dxf, lsk, lineWidth, contour);

            LwPolyline lfcq = Pus.AddPointsToLwPolyLine(lhead[1], lhead[4], lhead[5], lshank[7], lshank[3]);
            lfcq.IsClosed = true;
            fun.PolyFill(dxf, lfcq, lineWidth, contour);

            LwPolyline lfd0 = Pus.AddPointsToLwPolyLine(linserts[0], lhead[0], lhead[1], lhead[4], lhead[3]);
            fun.PolyFill(dxf, lfd0, lineWidth, contour);

            LwPolyline list0 = Pus.AddPointsToLwPolyLine(linserts[0], linserts[1], linserts[4], linserts[3]);
            list0.IsClosed = true;
            fun.PolyFill(dxf, list0, lineWidth, cutting);

            if (linserts[5].Y > linserts[4].Y)
            {
                LwPolyline lfiu = Pus.AddPointsToLwPolyLine(lhead[3], lhead[4], lhead[5], lhead[6], lhead[7], lhead[8]);
                lfiu.IsClosed = true;
                fun.PolyFill(dxf, lfiu, lineWidth, contour);

                LwPolyline lfcu = Pus.AddPointsToLwPolyLine(lhead[5], lhead[6], lshank[6], lshank[7]);
                lfcu.IsClosed = true;
                fun.PolyFill(dxf, lfcu, lineWidth, contour);

                LwPolyline listu = Pus.AddPointsToLwPolyLine(linserts[3], linserts[4], linserts[5]);
                listu.IsClosed = true;
                fun.PolyFill(dxf, listu, lineWidth, cutting);

            }
            //zview标注
            LinearDimension dim_h1 = new LinearDimension(new Line(zk, zhead[0]), offset, Pus.Degree(zshank[4], zshank[0]), dimensionStyle);
            fun.dxflinedim(dxf, dim_h1, h1);

            Vector2 z3 = Pus.ToV2(zinserts[3]);
            if (gammao == 0)
            {
                gammao = 0.1 * pi / 180;
                Pus.NeedleDim(dxf, new Line(z3, fun.Polar(z3, -pi / 2, 1)),
                    new Line(z3, fun.Polar(z3, -pi / 2 + gammao, 1)), offset * 1.7, "γo=0°", dimensionStyle);
            }
            else
            {
                Pus.NeedleDim(dxf, new Line(z3, fun.Polar(z3, -pi / 2, 1)),
                    new Line(z3, fun.Polar(z3, -pi / 2 + gammao, 1)), offset * 1.7, "γo=" + Math.Round(gammao * 180 / pi, 2) + "°", dimensionStyle);
            }

            //lview标注
            Vector2 list3 = Pus.ToV2(linserts[3]);
            if (lambdas == 0)
            {
                lambdas = 0.1 * pi / 180;
                Pus.NeedleDim(dxf, new Line(linserts[4], linserts[3]),
                    new Line(list3, fun.Polar(list3, Pus.AngleOnP(linserts[4], linserts[3]) + lambdas, 1)), offset * 1.3, "λs=0°", dimensionStyle);
            }
            else
            {
                Pus.NeedleDim(dxf, new Line(linserts[4], linserts[3]),
                    new Line(list3, fun.Polar(list3, Pus.AngleOnP(linserts[4], linserts[3]) + lambdas, 1)), offset * 1.3, "λs=" + Math.Round(lambdas * 180 / pi, 2) + "°", dimensionStyle);
            }
            LinearDimension dim_h2 = new LinearDimension(new Line(lshank[4], lshank[0]), offset, Pus.Degree(lshank[4], lshank[0]), dimensionStyle);
            fun.dxflinedim(dxf, dim_h2, h2);


            //图框
            Vector2 a3xsize = Frame.A3X;
            double isframe = 0;
            try
            {
                isframe = Convert.ToDouble(data["isframe"]);
            }
            catch (KeyNotFoundException) { }
            if (isframe != 0)
            {
                Vector2 EntitysCenter = new Vector2((shank[4].X + zhead[0].X) / 2, (shank[4].Y + lshank[0].Y) / 2);
                Vector2 p0 = new Vector2(EntitysCenter.X - a3xsize.X / 2, EntitysCenter.Y + a3xsize.Y / 2);
                Dictionary<string, Vector2> positions = Frame.frameA3X(dxf, p0);
                Vector2 kp = p0;
                try
                {
                    kp = positions["比例"];
                    fun.writetextofC(dxf, kscale + ":1", positions["比例"], 3.5, 0, 0.6, 3);
                }
                catch (Exception) { }
            }

            dxf.DrawingVariables.AcadVer = DxfVersion.AutoCad2007;
            dxf.Save(path);
        }
        public static void StyleJ_InsertV(Dictionary<string, Object> data)
        {
            DxfDocument dxf = new DxfDocument();
            Layer contour = new Layer("contour") { Color = AciColor.Cyan };    //1,轮廓层
            Layer cutting = new Layer("cutting") { Color = AciColor.Red };    //切削层

            string path = Convert.ToString(data["path"]);
            //参数名称取自ISO 5610-2
            double b = 12;
            double l1 = 70;
            double l2 = 25;
            double f = 16;
            double l3 = 11.1;
            double h2 = 12;
            double h1 = 12;
            double s = 3.18;
            double insertAngle = 35 * pi / 180;
            double alphan = 7 * pi / 180;
            double cutagl = 93 * pi / 180;
            double lambdas = 0;
            double gamao = 0;
            double repsilon = 0;
            #region
            try
            {
                if (data["re"] != null)
                    repsilon = Convert.ToDouble(data["re"]);
                if (repsilon <= 0)
                    repsilon = 0.01;
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["lams"] != null)
                    lambdas = Math.Abs(Convert.ToDouble(data["lams"]) * pi / 180);
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["gamo"] != null)
                    gamao = Math.Abs(Convert.ToDouble(data["gamo"]) * pi / 180);
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["b"] != null)
                    b = Convert.ToDouble(data["b"]);
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["s"] != null)
                    s = Convert.ToDouble(data["s"]);
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["lf"] != null)
                    l1 = Convert.ToDouble(data["lf"]);
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["lh"] != null)
                    l2 = Convert.ToDouble(data["lh"]);
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["wf"] != null)
                    f = Convert.ToDouble(data["wf"]);
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["h"] != null)
                    h2 = Convert.ToDouble(data["h"]);
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["hf"] != null)
                    h1 = Convert.ToDouble(data["hf"]);
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["epsr"] != null)
                    insertAngle = Convert.ToDouble(data["epsr"]) * pi / 180;
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["kapr"] != null)
                    cutagl = Convert.ToDouble(data["kapr"]) * pi / 180;
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["an"] != null)
                    alphan = Convert.ToDouble(data["an"]) * pi / 180;
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["ic"] != null)
                    l3 = Pus.GetLByIC(Convert.ToDouble(data["ic"]), insertAngle);
            }
            catch (KeyNotFoundException) { }
            #endregion
            double kscale = 1;
            if (l1 >= 120)
                kscale = 1;
            else
                kscale = 1.5;
            double lineWidth = 1;
            //k点位置恒定
            Vector3 k = new Vector3(0, 0, 0);
            Vector3 b2 = new Vector3(k.X + l1, k.Y + f, k.Z - h1);
            Vector3 b1 = new Vector3(b2.X, b2.Y - b, b2.Z);
            Vector3 b6 = new Vector3(k.X + l2, b1.Y, b1.Z);

            //刀杆顶面
            Vector3 u1 = new Vector3(b1.X, b1.Y, b1.Z + h2);
            Vector3 u2 = new Vector3(b2.X, b2.Y, b2.Z + h2);
            Vector3 u3 = new Vector3(b6.X, b2.Y, b2.Z + h2);
            double guai = kscale;
            Vector3 u3p = new Vector3(u3.X - guai, u3.Y, u3.Z);
            Vector3 u4 = new Vector3(b6.X, b6.Y, b6.Z + h2);
            Vector3 u4p = new Vector3(u4.X - guai, u4.Y, u4.Z);

            //Kp=fun.polar(K,0,r/tan((pi-kapr)/2)-r)
            //i4=fun.polar(Kp,kapr-pi,r/tan(epsr/2)-r/tan((pi-kapr)/2))
            Vector2 kp = fun.Polar(Vector2.Zero, 0, repsilon / Math.Tan((pi - cutagl) / 2) - repsilon);
            Vector2 twoi4 = fun.Polar(kp, cutagl - pi, repsilon / Math.Tan(insertAngle / 2) - repsilon / Math.Tan((pi - cutagl) / 2));
            Vector2[] twois = Pus.DiamondPoints(twoi4, l3, insertAngle, true, cutagl);
            Vector2 twoi1 = twois[1];
            Vector2 twoi2 = twois[2];
            Vector2 twoi3 = twois[3];
            double theoffset = Math.Tan(alphan) * s;
            Vector2[] twoiis = Pus.OffsetPoints(theoffset, twois);
            Vector2 twoii4 = twoiis[0];
            Vector2 twoii3 = twoiis[3];
            Vector2 twoii1 = twoiis[1];
            Vector2 twoii2 = twoiis[2];

            //刀头面
            Vector3 i4 = new Vector3(twoi4.X, twoi4.Y, k.Z);
            Vector3 i3 = new Vector3(twoi3.X, twoi3.Y, k.Z);
            Vector3 i2 = new Vector3(twoi2.X, twoi2.Y, k.Z);
            Vector3 i1 = new Vector3(twoi1.X, twoi1.Y, k.Z);
            Vector2 cnm = Pus.IntersOnP(i1, new Vector3(i1.X + 1, i1.Y, i1.Z), u3p, u4p);
            Vector3 dt1 = new Vector3(cnm.X, cnm.Y, u4.Z);
            Vector3 dt2 = u3p;
            Vector2 xx = Pus.IntersOnP(i3, i4, u2, u3);
            Vector3 dt4 = Pus.KPoint(i3, new Vector3(xx.X, xx.Y, u3.Z), 0.7);
            Vector3 dt3 = Pus.KPoint(u3, new Vector3(xx.X, xx.Y, u3.Z), 0.85);

            Vector3 bdt1 = new Vector3(dt1.X, dt1.Y, b1.Z);
            Vector3 b5 = new Vector3(twoii4.X, twoii4.Y, b1.Z);
            Vector3 b4 = new Vector3(dt4.X, dt4.Y, b1.Z);
            Vector3 b3 = new Vector3(dt3.X, dt3.Y, b1.Z);

            Vector3 ii4 = new Vector3(twoii4.X, twoii4.Y, k.Z - s);
            Vector3 ii3 = new Vector3(twoii3.X, twoii3.Y, k.Z - s);
            Vector3 ii1 = new Vector3(twoii1.X, twoii1.Y, k.Z - s);
            Vector3 ii2 = new Vector3(twoii2.X, twoii2.Y, k.Z - s);

            i4 = Pus.LinearTrans(kscale, i4);
            i3 = Pus.LinearTrans(kscale, i3);
            i2 = Pus.LinearTrans(kscale, i2);
            i1 = Pus.LinearTrans(kscale, i1);
            dt1 = Pus.LinearTrans(kscale, dt1);
            dt2 = Pus.LinearTrans(kscale, dt2);
            dt3 = Pus.LinearTrans(kscale, dt3);
            dt4 = Pus.LinearTrans(kscale, dt4);

            ii4 = Pus.LinearTrans(kscale, ii4);
            ii3 = Pus.LinearTrans(kscale, ii3);
            ii2 = Pus.LinearTrans(kscale, ii2);
            ii1 = Pus.LinearTrans(kscale, ii1);

            b1 = Pus.LinearTrans(kscale, b1);
            b2 = Pus.LinearTrans(kscale, b2);
            b3 = Pus.LinearTrans(kscale, b3);
            b4 = Pus.LinearTrans(kscale, b4);
            b5 = Pus.LinearTrans(kscale, b5);
            b6 = Pus.LinearTrans(kscale, b6);
            bdt1 = Pus.LinearTrans(kscale, bdt1);

            u1 = Pus.LinearTrans(kscale, u1);
            u2 = Pus.LinearTrans(kscale, u2);
            u3 = Pus.LinearTrans(kscale, u3);
            u3p = Pus.LinearTrans(kscale, u3p);
            u4 = Pus.LinearTrans(kscale, u4);


            //主视图
            LwPolyline mshank = Pus.AddPointsToLwPolyLine(u1, u2, u3, u4);
            mshank.IsClosed = true;
            fun.PolyFill(dxf, mshank, lineWidth, contour);

            LwPolyline minsert = Pus.AddPointsToLwPolyLine(i4, i1, i2, i3);
            minsert.IsClosed = true;
            Pus.AglToArc(minsert, repsilon);

            LwPolyline mhead = Pus.AddPointsToLwPolyLine(i3, i2, i1, dt1, dt2, dt3, dt4, i3);
            mhead.IsClosed = true;
            fun.PolyFill(dxf, mhead, lineWidth, contour);
            LwPolyline mheadc1 = Pus.AddPointsToLwPolyLine(dt1, u4);
            fun.PolyFill(dxf, mheadc1, lineWidth, contour);
            LwPolyline mheadc2 = Pus.AddPointsToLwPolyLine(dt2, u3);
            fun.PolyFill(dxf, mheadc2, lineWidth, contour);

            fun.PolyFill(dxf, minsert, lineWidth, cutting);
            //m视图标注
            DimensionStyle dimensionStyle = new DimensionStyle("mystyle");
            dimensionStyle.ArrowSize = kscale * 1.2;
            dimensionStyle.DimArrow1 = DimensionArrowhead.Closedfilled;
            dimensionStyle.DimArrow2 = DimensionArrowhead.Closedfilled;
            dimensionStyle.TextHeight = kscale;
            dimensionStyle.TextOffset = kscale / 2;
            double offset = 7 * kscale;
            LinearDimension dim_f = new LinearDimension(new Line(new Vector2(k.X, k.Y), new Vector2(b3.X, b3.Y)), offset * 1.5, Pus.Degree(b1, b2), dimensionStyle);
            fun.dxflinedim(dxf, dim_f, f);
            LinearDimension dim_l1 = new LinearDimension(new Line(new Vector2(k.X, k.Y), new Vector2(b1.X, b1.Y)), offset * 1.5, Pus.Degree(new Vector2(b1.X, b1.Y), new Vector2(b6.X, b6.Y)), dimensionStyle);
            fun.dxflinedim(dxf, dim_l1, l1);
            LinearDimension dim_l2 = new LinearDimension(new Line(new Vector2(k.X, k.Y), new Vector2(u4.X, u4.Y)), offset, Pus.Degree(new Vector2(u1.X, u1.Y), new Vector2(u4.X, u4.Y)), dimensionStyle);
            fun.dxflinedim(dxf, dim_l2, l2);
            //LinearDimension dim_l3 = new LinearDimension(new Line(i2, i3), offset, Pus.Degree(new Vector2(i3.X, i3.Y), new Vector2(i2.X, i2.Y)), dimensionStyle);
            //fun.dxflinedim(dxf, dim_l3, Math.Round(l3, 2));
            LinearDimension dim_b = new LinearDimension(new Line(new Vector2(u1.X, u1.Y), new Vector2(u2.X, u2.Y)), offset, Pus.Degree(new Vector2(u2.X, u2.Y), new Vector2(u1.X, u1.Y)), dimensionStyle);
            fun.dxflinedim(dxf, dim_b, b);
            //Angular2LineDimension dim_insertAgl = new Angular2LineDimension(new Line(i4, i3), new Line(i4, i1), offset * 0.5, dimensionStyle);
            //dim_insertAgl.UserText = Math.Round(insertAngle * 180 / pi, 2) + "°";
            //dxf.AddEntity(dim_insertAgl);
            Angular2LineDimension dim_cutagl = new Angular2LineDimension(new Line(i4, i1), new Line(new Vector2(i4.X, i4.Y), fun.Polar(new Vector2(i4.X, i4.Y), -pi / 2, 1)), offset * 0.4, dimensionStyle);
            dim_cutagl.UserText = Math.Round(cutagl * 180 / pi, 2) + "°";
            dxf.AddEntity(dim_cutagl);
            //RadialDimension dim_repsilon = new RadialDimension(Pus.GetArcFromPline(minsert, 1), Pus.Degree(i3, i4) - 10, offset * 0.5, dimensionStyle);
            //dim_repsilon.UserText = "rε=" + repsilon;
            //dxf.AddEntity(dim_repsilon);
            //放倒(所有点)尚未平移到下方，因为只能绕着原点k所在轴旋转
            Vector3 rotate = new Vector3(-1, 0, 0);
            double rotateAgl = pi / 2;
            i4 = Pus.Rodrigue(rotate, 1, rotateAgl, i4);
            i3 = Pus.Rodrigue(rotate, 1, rotateAgl, i3);
            i2 = Pus.Rodrigue(rotate, 1, rotateAgl, i2);
            i1 = Pus.Rodrigue(rotate, 1, rotateAgl, i1);
            dt1 = Pus.Rodrigue(rotate, 1, rotateAgl, dt1);
            dt2 = Pus.Rodrigue(rotate, 1, rotateAgl, dt2);
            dt3 = Pus.Rodrigue(rotate, 1, rotateAgl, dt3);
            dt4 = Pus.Rodrigue(rotate, 1, rotateAgl, dt4);
            ii4 = Pus.Rodrigue(rotate, 1, rotateAgl, ii4);
            ii3 = Pus.Rodrigue(rotate, 1, rotateAgl, ii3);
            ii2 = Pus.Rodrigue(rotate, 1, rotateAgl, ii2);
            ii1 = Pus.Rodrigue(rotate, 1, rotateAgl, ii1);

            b1 = Pus.Rodrigue(rotate, 1, rotateAgl, b1);
            b2 = Pus.Rodrigue(rotate, 1, rotateAgl, b2);
            b3 = Pus.Rodrigue(rotate, 1, rotateAgl, b3);
            b4 = Pus.Rodrigue(rotate, 1, rotateAgl, b4);
            b5 = Pus.Rodrigue(rotate, 1, rotateAgl, b5);
            b6 = Pus.Rodrigue(rotate, 1, rotateAgl, b6);
            bdt1 = Pus.Rodrigue(rotate, 1, rotateAgl, bdt1);

            u1 = Pus.Rodrigue(rotate, 1, rotateAgl, u1);
            u2 = Pus.Rodrigue(rotate, 1, rotateAgl, u2);
            u3 = Pus.Rodrigue(rotate, 1, rotateAgl, u3);
            u3p = Pus.Rodrigue(rotate, 1, rotateAgl, u3p);
            u4 = Pus.Rodrigue(rotate, 1, rotateAgl, u4);

            //创建lambds
            rotate = new Vector3(Math.Sin(cutagl - pi / 2), k.Z, Math.Cos(cutagl - pi / 2));
            rotateAgl = lambdas;
            i4 = Pus.Rodrigue(rotate, 1, rotateAgl, i4);
            i3 = Pus.Rodrigue(rotate, 1, rotateAgl, i3);
            i2 = Pus.Rodrigue(rotate, 1, rotateAgl, i2);
            i1 = Pus.Rodrigue(rotate, 1, rotateAgl, i1);
            ii4 = Pus.Rodrigue(rotate, 1, rotateAgl, ii4);
            ii3 = Pus.Rodrigue(rotate, 1, rotateAgl, ii3);
            ii2 = Pus.Rodrigue(rotate, 1, rotateAgl, ii2);
            ii1 = Pus.Rodrigue(rotate, 1, rotateAgl, ii1);
            dt1 = Pus.Rodrigue(rotate, 1, rotateAgl, dt1);
            dt2 = Pus.Rodrigue(rotate, 1, rotateAgl, dt2);
            dt3 = Pus.Rodrigue(rotate, 1, rotateAgl, dt3);
            dt4 = Pus.Rodrigue(rotate, 1, rotateAgl, dt4);

            //创建gamo
            double disi1_i4 = Vector3.Distance(i1, i4);
            rotate = (i1 - i4) / disi1_i4;
            rotateAgl = gamao;
            i4 = Pus.Rodrigue(rotate, 1, rotateAgl, i4);
            i3 = Pus.Rodrigue(rotate, 1, rotateAgl, i3);
            i2 = Pus.Rodrigue(rotate, 1, rotateAgl, i2);
            i1 = Pus.Rodrigue(rotate, 1, rotateAgl, i1);
            ii4 = Pus.Rodrigue(rotate, 1, rotateAgl, ii4);
            ii3 = Pus.Rodrigue(rotate, 1, rotateAgl, ii3);
            ii2 = Pus.Rodrigue(rotate, 1, rotateAgl, ii2);
            ii1 = Pus.Rodrigue(rotate, 1, rotateAgl, ii1);
            dt1 = Pus.Rodrigue(rotate, 1, rotateAgl, dt1);
            dt2 = Pus.Rodrigue(rotate, 1, rotateAgl, dt2);
            dt3 = Pus.Rodrigue(rotate, 1, rotateAgl, dt3);
            dt4 = Pus.Rodrigue(rotate, 1, rotateAgl, dt4);

            //重新计算刀头的点
            Face3d face4dt = new Face3d(dt2, dt3, dt4);
            Vector3 v4dt = u2 - b2;
            dt1 = Pus.Inters(face4dt, new Line(bdt1, bdt1 + v4dt));
            dt2 = Pus.Inters(face4dt, new Line(u3p, u3p + v4dt));
            dt3 = Pus.Inters(face4dt, new Line(b3, b3 + v4dt));
            dt4 = Pus.Inters(face4dt, new Line(b4, b4 + v4dt));

            Face3d face4buttom = new Face3d(b1, b2, b3);
            b5 = Pus.Inters(face4buttom, new Line(ii4, ii4 + v4dt));
            Vector3 bx = Pus.Inters(face4buttom, new Line(ii1, ii1 + v4dt));
            bdt1 = Pus.Inters(face4buttom, new Line(dt1, dt1 + v4dt));

            //平移所有点到下方
            Vector3 voff = new Vector3(0, -b * kscale - offset * 1.5, 0);
            Vector3 mk = Pus.OffsetXY(voff, k);
            Vector3 mi4 = Pus.OffsetXY(voff, i4);
            Vector3 mi3 = Pus.OffsetXY(voff, i3);
            Vector3 mi2 = Pus.OffsetXY(voff, i2);
            Vector3 mi1 = Pus.OffsetXY(voff, i1);
            Vector3 mdt1 = Pus.OffsetXY(voff, dt1);
            Vector3 mdt2 = Pus.OffsetXY(voff, dt2);
            Vector3 mdt3 = Pus.OffsetXY(voff, dt3);
            Vector3 mdt4 = Pus.OffsetXY(voff, dt4);
            Vector3 mii4 = Pus.OffsetXY(voff, ii4);
            Vector3 mii3 = Pus.OffsetXY(voff, ii3);
            Vector3 mii2 = Pus.OffsetXY(voff, ii2);
            Vector3 mii1 = Pus.OffsetXY(voff, ii1);

            Vector3 mb1 = Pus.OffsetXY(voff, b1);
            Vector3 mb2 = Pus.OffsetXY(voff, b2);
            Vector3 mb3 = Pus.OffsetXY(voff, b3);
            Vector3 mb4 = Pus.OffsetXY(voff, b4);
            Vector3 mb5 = Pus.OffsetXY(voff, b5);
            Vector3 mb6 = Pus.OffsetXY(voff, b6);
            Vector3 mbx = Pus.OffsetXY(voff, bx);
            Vector3 mbdt1 = Pus.OffsetXY(voff, bdt1);

            Vector3 mu1 = Pus.OffsetXY(voff, u1);
            Vector3 mu2 = Pus.OffsetXY(voff, u2);
            Vector3 mu3 = Pus.OffsetXY(voff, u3);
            Vector3 mu4 = Pus.OffsetXY(voff, u4);

            LwPolyline lshank = Pus.AddPointsToLwPolyLine(mb1, mu1, mu4, mb6);
            lshank.IsClosed = true;
            fun.PolyFill(dxf, lshank, lineWidth, contour);
            LwPolyline lshank_dt = Pus.AddPointsToLwPolyLine(mdt1, mu4);
            fun.PolyFill(dxf, lshank_dt, lineWidth, contour);
            LwPolyline lshank_dt1 = Pus.AddPointsToLwPolyLine(mdt2, mu3);
            fun.PolyFill(dxf, lshank_dt1, lineWidth, contour);

            LwPolyline lhead = Pus.AddPointsToLwPolyLine(mii4, mb5, mbdt1, mdt1);
            fun.PolyFill(dxf, lhead, lineWidth, contour);
            LwPolyline lhead1 = Pus.AddPointsToLwPolyLine(mbdt1, mb6);
            fun.PolyFill(dxf, lhead1, lineWidth, contour);
            LwPolyline lhead2 = Pus.AddPointsToLwPolyLine(mdt1, mi1);
            fun.PolyFill(dxf, lhead2, lineWidth, contour);
            LwPolyline lhead3 = Pus.AddPointsToLwPolyLine(mdt1, mbdt1);
            fun.PolyFill(dxf, lhead3, lineWidth, contour);
            LwPolyline lhead4 = Pus.AddPointsToLwPolyLine(mbx, mii1);
            fun.PolyFill(dxf, lhead4, lineWidth, contour);
            if (gamao > 0)
            {
                LwPolyline lheadu = Pus.AddPointsToLwPolyLine(mi1, mdt1, mdt2, mdt3, mdt4, mi3);
                fun.PolyFill(dxf, lheadu, lineWidth, contour);

                LwPolyline linsertu = Pus.AddPointsToLwPolyLine(mi4, mi1, mi2, mi3);
                linsertu.IsClosed = true;
                fun.PolyFill(dxf, linsertu, lineWidth, cutting);
            }

            LwPolyline linsertf = Pus.AddPointsToLwPolyLine(mi4, mii4, mii1, mi1);
            linsertf.IsClosed = true;
            fun.PolyFill(dxf, linsertf, lineWidth, cutting);
            //l视图标注
            LinearDimension dim_h1 = new LinearDimension(new Line(new Vector2(mk.X, mk.Y), new Vector2(mb5.X, mb5.Y)), offset * 0.5, Pus.Degree(b1, u1), dimensionStyle);
            fun.dxflinedim(dxf, dim_h1, h1);
            LinearDimension dim_h2 = new LinearDimension(new Line(new Vector2(mu1.X, mu1.Y), new Vector2(mb1.X, mb1.Y)), offset, Pus.Degree(u1, b1), dimensionStyle);
            fun.dxflinedim(dxf, dim_h2, h2);
            if (lambdas == 0)
                Pus.NeedleDim(dxf, new Line(new Vector2(mi4.X, mi4.Y), fun.Polar(new Vector2(mi4.X, mi4.Y), pi / 180, 1)), new Line(mi4, mi4 + mu4 - mu2), kscale * offset, "λs=0°", dimensionStyle);
            else
                Pus.NeedleDim(dxf, new Line(mi4, mi1), new Line(mi4, mi4 + mu4 - mu2), kscale * offset, "λs=" + Math.Round(lambdas * 180 / pi, 2) + "°", dimensionStyle);
            //左视图
            //所有点移动到原点
            //立正
            rotate = new Vector3(1, 0, 0);
            rotateAgl = pi / 2;
            Vector3 zi4 = Pus.Rodrigue(rotate, 1, rotateAgl, i4);
            Vector3 zi3 = Pus.Rodrigue(rotate, 1, rotateAgl, i3);
            Vector3 zi2 = Pus.Rodrigue(rotate, 1, rotateAgl, i2);
            Vector3 zi1 = Pus.Rodrigue(rotate, 1, rotateAgl, i1);
            Vector3 zdt1 = Pus.Rodrigue(rotate, 1, rotateAgl, dt1);
            Vector3 zdt2 = Pus.Rodrigue(rotate, 1, rotateAgl, dt2);
            Vector3 zdt3 = Pus.Rodrigue(rotate, 1, rotateAgl, dt3);
            Vector3 zdt4 = Pus.Rodrigue(rotate, 1, rotateAgl, dt4);

            Vector3 zii4 = Pus.Rodrigue(rotate, 1, rotateAgl, ii4);
            Vector3 zii3 = Pus.Rodrigue(rotate, 1, rotateAgl, ii3);
            Vector3 zii2 = Pus.Rodrigue(rotate, 1, rotateAgl, ii2);
            Vector3 zii1 = Pus.Rodrigue(rotate, 1, rotateAgl, ii1);

            Vector3 zb1 = Pus.Rodrigue(rotate, 1, rotateAgl, b1);
            Vector3 zb2 = Pus.Rodrigue(rotate, 1, rotateAgl, b2);
            Vector3 zb3 = Pus.Rodrigue(rotate, 1, rotateAgl, b3);
            Vector3 zb4 = Pus.Rodrigue(rotate, 1, rotateAgl, b4);
            Vector3 zb5 = Pus.Rodrigue(rotate, 1, rotateAgl, b5);
            Vector3 zb6 = Pus.Rodrigue(rotate, 1, rotateAgl, b6);
            Vector3 zbx = Pus.Rodrigue(rotate, 1, rotateAgl, bx);
            Vector3 zbdt1 = Pus.Rodrigue(rotate, 1, rotateAgl, bdt1);

            Vector3 zu1 = Pus.Rodrigue(rotate, 1, rotateAgl, u1);
            Vector3 zu2 = Pus.Rodrigue(rotate, 1, rotateAgl, u2);
            Vector3 zu3 = Pus.Rodrigue(rotate, 1, rotateAgl, u3);
            Vector3 zu4 = Pus.Rodrigue(rotate, 1, rotateAgl, u4);

            //绕y转，露出左面
            rotate = new Vector3(0, 1, 0);
            rotateAgl = pi / 2;
            zi4 = Pus.Rodrigue(rotate, 1, rotateAgl, zi4);
            zi3 = Pus.Rodrigue(rotate, 1, rotateAgl, zi3);
            zi2 = Pus.Rodrigue(rotate, 1, rotateAgl, zi2);
            zi1 = Pus.Rodrigue(rotate, 1, rotateAgl, zi1);
            zdt1 = Pus.Rodrigue(rotate, 1, rotateAgl, zdt1);
            zdt2 = Pus.Rodrigue(rotate, 1, rotateAgl, zdt2);
            zdt3 = Pus.Rodrigue(rotate, 1, rotateAgl, zdt3);
            zdt4 = Pus.Rodrigue(rotate, 1, rotateAgl, zdt4);

            zii4 = Pus.Rodrigue(rotate, 1, rotateAgl, zii4);
            zii3 = Pus.Rodrigue(rotate, 1, rotateAgl, zii3);
            zii2 = Pus.Rodrigue(rotate, 1, rotateAgl, zii2);
            zii1 = Pus.Rodrigue(rotate, 1, rotateAgl, zii1);

            zb1 = Pus.Rodrigue(rotate, 1, rotateAgl, zb1);
            zb2 = Pus.Rodrigue(rotate, 1, rotateAgl, zb2);
            zb3 = Pus.Rodrigue(rotate, 1, rotateAgl, zb3);
            zb4 = Pus.Rodrigue(rotate, 1, rotateAgl, zb4);
            zb5 = Pus.Rodrigue(rotate, 1, rotateAgl, zb5);
            zb6 = Pus.Rodrigue(rotate, 1, rotateAgl, zb6);
            zbx = Pus.Rodrigue(rotate, 1, rotateAgl, zbx);
            zbdt1 = Pus.Rodrigue(rotate, 1, rotateAgl, zbdt1);

            zu1 = Pus.Rodrigue(rotate, 1, rotateAgl, zu1);
            zu2 = Pus.Rodrigue(rotate, 1, rotateAgl, zu2);
            zu3 = Pus.Rodrigue(rotate, 1, rotateAgl, zu3);
            zu4 = Pus.Rodrigue(rotate, 1, rotateAgl, zu4);

            //平移
            voff = new Vector3(-b * kscale - offset * 2, 0, 0);
            zi4 = Pus.OffsetXY(voff, zi4);
            zi3 = Pus.OffsetXY(voff, zi3);
            zi2 = Pus.OffsetXY(voff, zi2);
            zi1 = Pus.OffsetXY(voff, zi1);
            zdt1 = Pus.OffsetXY(voff, zdt1);
            zdt2 = Pus.OffsetXY(voff, zdt2);
            zdt3 = Pus.OffsetXY(voff, zdt3);
            zdt4 = Pus.OffsetXY(voff, zdt4);

            zii4 = Pus.OffsetXY(voff, zii4);
            zii3 = Pus.OffsetXY(voff, zii3);
            zii2 = Pus.OffsetXY(voff, zii2);
            zii1 = Pus.OffsetXY(voff, zii1);

            zb1 = Pus.OffsetXY(voff, zb1);
            zb2 = Pus.OffsetXY(voff, zb2);
            zb3 = Pus.OffsetXY(voff, zb3);
            zb4 = Pus.OffsetXY(voff, zb4);
            zb5 = Pus.OffsetXY(voff, zb5);
            zb6 = Pus.OffsetXY(voff, zb6);
            zbx = Pus.OffsetXY(voff, zbx);
            zbdt1 = Pus.OffsetXY(voff, zbdt1);

            zu1 = Pus.OffsetXY(voff, zu1);
            zu2 = Pus.OffsetXY(voff, zu2);
            zu3 = Pus.OffsetXY(voff, zu3);
            zu4 = Pus.OffsetXY(voff, zu4);

            //左视图绘制
            LwPolyline zshank = Pus.AddPointsToLwPolyLine(zii4, zb5, zb4, zb3, zdt3, zdt4, zi3);
            fun.PolyFill(dxf, zshank, lineWidth, contour);
            LwPolyline zshank2 = Pus.AddPointsToLwPolyLine(zb4, zdt4);
            fun.PolyFill(dxf, zshank2, lineWidth, contour);
            if (lambdas > 0)
            {
                LwPolyline zshank1 = Pus.AddPointsToLwPolyLine(zdt3, zdt2, zdt1, zi1);
                fun.PolyFill(dxf, zshank1, lineWidth, contour);

                LwPolyline zinsert = Pus.AddPointsToLwPolyLine(zi4, zi1, zi2, zi3);
                zinsert.IsClosed = true;
                fun.PolyFill(dxf, zinsert, lineWidth, cutting);
            }

            LwPolyline zlen1 = Pus.AddPointsToLwPolyLine(zi3, zii3, zii4, zi4);
            zlen1.IsClosed = true;
            fun.PolyFill(dxf, zlen1, lineWidth, cutting);

            if (cutagl < pi / 2)
            {
                LwPolyline zlen2 = Pus.AddPointsToLwPolyLine(zii4, zii1, zi1, zi4);
                fun.PolyFill(dxf, zlen2, lineWidth, cutting);
            }
            //if (zdt1.Y > zu4.Y)
            //{
            //    Vector2 visible = Pus.IntersOnP(zi4, zi1, zb4, zu4);
            //    LwPolyline visiLine = Pus.AddPointsToLwPolyLine(zdt1, zu4);
            //    Pus.AddPointsToLwPolyLine(visiLine, visible);
            //    fun.PolyFill(dxf, visiLine, lineWidth, contour);
            //}
            //左视图标注
            //刃倾角
            if (gamao == 0)
                Pus.NeedleDim(dxf, new Line(new Vector2(zi4.X, zi4.Y), fun.Polar(new Vector2(zi4.X, zi4.Y), Pus.AngleOnP(zi3, zi4) + pi / 180, 1)), new Line(zi3, zi4), offset * 1.5, "γo=0°", dimensionStyle);
            else
                Pus.NeedleDim(dxf, new Line(zi3, zi4), new Line(new Vector2(zi4.X, zi4.Y), fun.Polar(new Vector2(zi4.X, zi4.Y), Pus.AngleOnP(zi3, zi4) + gamao, 1)), offset * 1.5, "γo=" + Math.Round(lambdas * 180 / pi, 2) + "°", dimensionStyle);

            //LinearDimension dim_s = new LinearDimension(new Line(zi4, zii4), offset, Pus.Degree(zi4, zi3) + 90, dimensionStyle);
            //fun.dxflinedim(dxf, dim_s, s);

            //后角
            if (alphan == 0)
                Pus.NeedleDim(dxf, new Line(zi4, zii4), new Line(new Vector2(zi4.X, zi4.Y), fun.Polar(new Vector2(zi4.X, zi4.Y), Pus.AngleOnP(zi4, zii4) + pi / 180, 1)), offset + h1 * kscale, "αn=0°", dimensionStyle);
            else
                Pus.NeedleDim(dxf, new Line(zi4, zii4), new Line(new Vector2(zi4.X, zi4.Y), fun.Polar(new Vector2(zi4.X, zi4.Y), Pus.AngleOnP(zi4, zii4) + alphan, 1)), offset + h1 * kscale, "αn=" + Math.Round(alphan * 180 / pi, 2) + "°", dimensionStyle);
            //图框
            if (Convert.ToDouble(data["isframe"]) == 1)
            {
                Vector2 c4c = new Vector2((b2.X + zb3.X) / 2, (b2.Y + mu1.Y) / 2);
                Dictionary<string, Vector2> positions = Frame.frameA3X(dxf, new Vector2(c4c.X - 420 / 2, c4c.Y + 297 / 2), new Dictionary<string, object>());
                fun.writetextofC(dxf, kscale + ":1", positions["比例"], 3.5, 0, 0.6, 3);
            }

            dxf.DrawingVariables.AcadVer = DxfVersion.AutoCad2007;
            dxf.Save(path);
        }
        /*//R型刀头 横小
        public static void StyleR_InsertS(Dictionary<string, Object> data) {

            DxfDocument dxf = new DxfDocument();
            Layer contour = new Layer("contour") { Color = AciColor.Cyan };    //1,轮廓层
            Layer cutting = new Layer("cutting") { Color = AciColor.Red };    //切削层

            string path = Convert.ToString(data["path"]);
            //参数名称取自ISO 5610
            double b = 12;
            double l1 = 70;
            double l2 = 25;
            double f = 10;
            double l3 = 7.52;
            double h2 = 12;
            double h1 = 12;
            double s = 2.38;
            double insertAngle = 90 * pi / 180;
            double alphan = 7 * pi / 180;
            double cutagl = 75 * pi / 180;
            double lambdas = 0;
            double gamao = 0;
            double repsilon = 0;
            #region
            try
            {
                if (data["re"] != null)
                    repsilon = Convert.ToDouble(data["re"]);
                if (repsilon <= 0)
                    repsilon = 0.01;
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["lams"] != null)
                    lambdas = Math.Abs(Convert.ToDouble(data["lams"]) * pi / 180);
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["gamo"] != null)
                    gamao = Math.Abs(Convert.ToDouble(data["gamo"]) * pi / 180);
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["b"] != null)
                    b = Convert.ToDouble(data["b"]);
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["s"] != null)
                    s = Convert.ToDouble(data["s"]);
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["lf"] != null)
                    l1 = Convert.ToDouble(data["lf"]);
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["lh"] != null)
                    l2 = Convert.ToDouble(data["lh"]);
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["wf"] != null)
                    f = Convert.ToDouble(data["wf"]);
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["h"] != null)
                    h2 = Convert.ToDouble(data["h"]);
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["hf"] != null)
                    h1 = Convert.ToDouble(data["hf"]);
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["epsr"] != null)
                    insertAngle = Convert.ToDouble(data["epsr"]) * pi / 180;
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["kapr"] != null)
                    cutagl = Convert.ToDouble(data["kapr"]) * pi / 180;
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["an"] != null)
                    alphan = Convert.ToDouble(data["an"]) * pi / 180;
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["l"] != null)
                    l3 = Convert.ToDouble(data["l"]);
            }
            catch (KeyNotFoundException) { }
            #endregion
            double kscale = 1;
            if (l1 >= 120)
                kscale = 1;
            else
                kscale = 1.5;
            double lineWidth = 1;
            //k点位置恒定
            Vector3 k = new Vector3(0, 0, 0);
            Vector3 b2 = new Vector3(k.X + l1, k.Y + f, k.Z - h1);
            Vector3 b1 = new Vector3(b2.X, b2.Y - b, b2.Z);
            Vector3 b6 = new Vector3(k.X + l2, b1.Y, b1.Z);

            //刀杆顶面
            Vector3 u1 = new Vector3(b1.X, b1.Y, b1.Z + h2);
            Vector3 u2 = new Vector3(b2.X, b2.Y, b2.Z + h2);
            Vector3 u3 = new Vector3(b6.X, b2.Y, b2.Z + h2);
            double guai = kscale;
            Vector3 u3p = new Vector3(u3.X - guai, u3.Y, u3.Z);
            Vector3 u4 = new Vector3(b6.X, b6.Y, b6.Z + h2);
            Vector3 u4p = new Vector3(u4.X - guai, u4.Y, u4.Z);

            //i4 = fun.polar(K,kapr-pi,r(1/tan(epsr/2)-1/tan((pi-karp)/2)))
            Vector2 twoi4 = fun.Polar(Vector2.Zero, cutagl - pi, repsilon / Math.Tan(insertAngle / 2) - repsilon / Math.Tan((pi - cutagl) / 2));
            Vector2[] twois = Pus.DiamondPoints(twoi4, l3, insertAngle, true, cutagl);
            Vector2 twoi1 = twois[1];
            Vector2 twoi2 = twois[2];
            Vector2 twoi3 = twois[3];
            double theoffset = Math.Tan(alphan) * s;
            Vector2[] twoiis = Pus.OffsetPoints(theoffset, twois);
            Vector2 twoii4 = twoiis[0];
            Vector2 twoii3 = twoiis[3];
            Vector2 twoii1 = twoiis[1];
            Vector2 twoii2 = twoiis[2];

            //刀头面
            Vector3 i4 = new Vector3(twoi4.X, twoi4.Y, k.Z);
            Vector3 i3 = new Vector3(twoi3.X, twoi3.Y, k.Z);
            Vector3 i2 = new Vector3(twoi2.X, twoi2.Y, k.Z);
            Vector3 i1 = new Vector3(twoi1.X, twoi1.Y, k.Z);
            Vector2 cnm = Pus.IntersOnP(i1, new Vector3(i1.X + 1, i1.Y, i1.Z), u3p, u4p);
            Vector3 dt1 = new Vector3(cnm.X, cnm.Y, u4.Z);
            Vector3 dt2 = u3p;
            Vector2 xx = Pus.IntersOnP(i3, i4, u2, u3);
            Vector3 dt4 = Pus.KPoint(i3, new Vector3(xx.X, xx.Y, u3.Z), 0.7);
            Vector3 dt3 = Pus.KPoint(u3, new Vector3(xx.X, xx.Y, u3.Z), 0.85);

            Vector3 bdt1 = new Vector3(dt1.X, dt1.Y, b1.Z);
            Vector3 b5 = new Vector3(twoii4.X, twoii4.Y, b1.Z);
            Vector3 b4 = new Vector3(dt4.X, dt4.Y, b1.Z);
            Vector3 b3 = new Vector3(dt3.X, dt3.Y, b1.Z);

            Vector3 ii4 = new Vector3(twoii4.X, twoii4.Y, k.Z - s);
            Vector3 ii3 = new Vector3(twoii3.X, twoii3.Y, k.Z - s);
            Vector3 ii1 = new Vector3(twoii1.X, twoii1.Y, k.Z - s);
            Vector3 ii2 = new Vector3(twoii2.X, twoii2.Y, k.Z - s);

            i4 = Pus.LinearTrans(kscale, i4);
            i3 = Pus.LinearTrans(kscale, i3);
            i2 = Pus.LinearTrans(kscale, i2);
            i1 = Pus.LinearTrans(kscale, i1);
            dt1 = Pus.LinearTrans(kscale, dt1);
            dt2 = Pus.LinearTrans(kscale, dt2);
            dt3 = Pus.LinearTrans(kscale, dt3);
            dt4 = Pus.LinearTrans(kscale, dt4);

            ii4 = Pus.LinearTrans(kscale, ii4);
            ii3 = Pus.LinearTrans(kscale, ii3);
            ii2 = Pus.LinearTrans(kscale, ii2);
            ii1 = Pus.LinearTrans(kscale, ii1);

            b1 = Pus.LinearTrans(kscale, b1);
            b2 = Pus.LinearTrans(kscale, b2);
            b3 = Pus.LinearTrans(kscale, b3);
            b4 = Pus.LinearTrans(kscale, b4);
            b5 = Pus.LinearTrans(kscale, b5);
            b6 = Pus.LinearTrans(kscale, b6);
            bdt1 = Pus.LinearTrans(kscale, bdt1);

            u1 = Pus.LinearTrans(kscale, u1);
            u2 = Pus.LinearTrans(kscale, u2);
            u3 = Pus.LinearTrans(kscale, u3);
            u3p = Pus.LinearTrans(kscale, u3p);
            u4 = Pus.LinearTrans(kscale, u4);


            //主视图
            LwPolyline mshank = Pus.AddPointsToLwPolyLine(u1, u2, u3, u4);
            mshank.IsClosed = true;
            fun.PolyFill(dxf, mshank, lineWidth, contour);

            LwPolyline minsert = Pus.AddPointsToLwPolyLine(i4, i1, i2, i3);
            minsert.IsClosed = true;
            Pus.AglToArc(minsert, repsilon);

            LwPolyline mhead = Pus.AddPointsToLwPolyLine(i3, i2, i1, dt1, dt2, dt3, dt4, i3);
            mhead.IsClosed = true;
            fun.PolyFill(dxf, mhead, lineWidth, contour);
            LwPolyline mheadc1 = Pus.AddPointsToLwPolyLine(dt1, u4);
            fun.PolyFill(dxf, mheadc1, lineWidth, contour);
            LwPolyline mheadc2 = Pus.AddPointsToLwPolyLine(dt2, u3);
            fun.PolyFill(dxf, mheadc2, lineWidth, contour);

            fun.PolyFill(dxf, minsert, lineWidth, cutting);
            //m视图标注
            DimensionStyle dimensionStyle = new DimensionStyle("mystyle");
            dimensionStyle.ArrowSize = kscale * 1.2;
            dimensionStyle.DimArrow1 = DimensionArrowhead.Closedfilled;
            dimensionStyle.DimArrow2 = DimensionArrowhead.Closedfilled;
            dimensionStyle.TextHeight = kscale;
            dimensionStyle.TextOffset = kscale / 2;
            double offset = 7 * kscale;
            LinearDimension dim_f = new LinearDimension(new Line(new Vector2(k.X, k.Y), new Vector2(b3.X, b3.Y)), offset * 1.5, Pus.Degree(b1, b2), dimensionStyle);
            fun.dxflinedim(dxf, dim_f, f);
            LinearDimension dim_l1 = new LinearDimension(new Line(new Vector2(k.X, k.Y), new Vector2(b1.X, b1.Y)), offset * 1.5, Pus.Degree(new Vector2(b1.X, b1.Y), new Vector2(b6.X, b6.Y)), dimensionStyle);
            fun.dxflinedim(dxf, dim_l1, l1);
            LinearDimension dim_l2 = new LinearDimension(new Line(new Vector2(k.X, k.Y), new Vector2(u4.X, u4.Y)), offset, Pus.Degree(new Vector2(u1.X, u1.Y), new Vector2(u4.X, u4.Y)), dimensionStyle);
            fun.dxflinedim(dxf, dim_l2, l2);
            //LinearDimension dim_l3 = new LinearDimension(new Line(i2, i3), offset, Pus.Degree(new Vector2(i3.X, i3.Y), new Vector2(i2.X, i2.Y)), dimensionStyle);
            //fun.dxflinedim(dxf, dim_l3, Math.Round(l3, 2));
            LinearDimension dim_b = new LinearDimension(new Line(new Vector2(u1.X, u1.Y), new Vector2(u2.X, u2.Y)), offset, Pus.Degree(new Vector2(u2.X, u2.Y), new Vector2(u1.X, u1.Y)), dimensionStyle);
            fun.dxflinedim(dxf, dim_b, b);
            //Angular2LineDimension dim_insertAgl = new Angular2LineDimension(new Line(i4, i3), new Line(i4, i1), offset * 0.5, dimensionStyle);
            //dim_insertAgl.UserText = Math.Round(insertAngle * 180 / pi, 2) + "°";
            //dxf.AddEntity(dim_insertAgl);
            Angular2LineDimension dim_cutagl = new Angular2LineDimension(new Line(i4, i1), new Line(new Vector2(i4.X, i4.Y), fun.Polar(new Vector2(i4.X, i4.Y), -pi / 2, 1)), offset * 0.4, dimensionStyle);
            dim_cutagl.UserText = Math.Round(cutagl * 180 / pi, 2) + "°";
            dxf.AddEntity(dim_cutagl);
            //RadialDimension dim_repsilon = new RadialDimension(Pus.GetArcFromPline(minsert, 1), Pus.Degree(i3, i4) - 10, offset * 0.5, dimensionStyle);
            //dim_repsilon.UserText = "rε=" + repsilon;
            //dxf.AddEntity(dim_repsilon);
            //放倒(所有点)尚未平移到下方，因为只能绕着原点k所在轴旋转
            Vector3 rotate = new Vector3(-1, 0, 0);
            double rotateAgl = pi / 2;
            i4 = Pus.Rodrigue(rotate, 1, rotateAgl, i4);
            i3 = Pus.Rodrigue(rotate, 1, rotateAgl, i3);
            i2 = Pus.Rodrigue(rotate, 1, rotateAgl, i2);
            i1 = Pus.Rodrigue(rotate, 1, rotateAgl, i1);
            dt1 = Pus.Rodrigue(rotate, 1, rotateAgl, dt1);
            dt2 = Pus.Rodrigue(rotate, 1, rotateAgl, dt2);
            dt3 = Pus.Rodrigue(rotate, 1, rotateAgl, dt3);
            dt4 = Pus.Rodrigue(rotate, 1, rotateAgl, dt4);
            ii4 = Pus.Rodrigue(rotate, 1, rotateAgl, ii4);
            ii3 = Pus.Rodrigue(rotate, 1, rotateAgl, ii3);
            ii2 = Pus.Rodrigue(rotate, 1, rotateAgl, ii2);
            ii1 = Pus.Rodrigue(rotate, 1, rotateAgl, ii1);

            b1 = Pus.Rodrigue(rotate, 1, rotateAgl, b1);
            b2 = Pus.Rodrigue(rotate, 1, rotateAgl, b2);
            b3 = Pus.Rodrigue(rotate, 1, rotateAgl, b3);
            b4 = Pus.Rodrigue(rotate, 1, rotateAgl, b4);
            b5 = Pus.Rodrigue(rotate, 1, rotateAgl, b5);
            b6 = Pus.Rodrigue(rotate, 1, rotateAgl, b6);
            bdt1 = Pus.Rodrigue(rotate, 1, rotateAgl, bdt1);

            u1 = Pus.Rodrigue(rotate, 1, rotateAgl, u1);
            u2 = Pus.Rodrigue(rotate, 1, rotateAgl, u2);
            u3 = Pus.Rodrigue(rotate, 1, rotateAgl, u3);
            u3p = Pus.Rodrigue(rotate, 1, rotateAgl, u3p);
            u4 = Pus.Rodrigue(rotate, 1, rotateAgl, u4);

            //创建lambds
            rotate = new Vector3(Math.Sin(cutagl - pi / 2), k.Z, Math.Cos(cutagl - pi / 2));
            rotateAgl = lambdas;
            i4 = Pus.Rodrigue(rotate, 1, rotateAgl, i4);
            i3 = Pus.Rodrigue(rotate, 1, rotateAgl, i3);
            i2 = Pus.Rodrigue(rotate, 1, rotateAgl, i2);
            i1 = Pus.Rodrigue(rotate, 1, rotateAgl, i1);
            ii4 = Pus.Rodrigue(rotate, 1, rotateAgl, ii4);
            ii3 = Pus.Rodrigue(rotate, 1, rotateAgl, ii3);
            ii2 = Pus.Rodrigue(rotate, 1, rotateAgl, ii2);
            ii1 = Pus.Rodrigue(rotate, 1, rotateAgl, ii1);
            dt1 = Pus.Rodrigue(rotate, 1, rotateAgl, dt1);
            dt2 = Pus.Rodrigue(rotate, 1, rotateAgl, dt2);
            dt3 = Pus.Rodrigue(rotate, 1, rotateAgl, dt3);
            dt4 = Pus.Rodrigue(rotate, 1, rotateAgl, dt4);

            //创建gamo
            double disi1_i4 = Vector3.Distance(i1, i4);
            rotate = (i1 - i4) / disi1_i4;
            rotateAgl = gamao;
            i4 = Pus.Rodrigue(rotate, 1, rotateAgl, i4);
            i3 = Pus.Rodrigue(rotate, 1, rotateAgl, i3);
            i2 = Pus.Rodrigue(rotate, 1, rotateAgl, i2);
            i1 = Pus.Rodrigue(rotate, 1, rotateAgl, i1);
            ii4 = Pus.Rodrigue(rotate, 1, rotateAgl, ii4);
            ii3 = Pus.Rodrigue(rotate, 1, rotateAgl, ii3);
            ii2 = Pus.Rodrigue(rotate, 1, rotateAgl, ii2);
            ii1 = Pus.Rodrigue(rotate, 1, rotateAgl, ii1);
            dt1 = Pus.Rodrigue(rotate, 1, rotateAgl, dt1);
            dt2 = Pus.Rodrigue(rotate, 1, rotateAgl, dt2);
            dt3 = Pus.Rodrigue(rotate, 1, rotateAgl, dt3);
            dt4 = Pus.Rodrigue(rotate, 1, rotateAgl, dt4);

            //重新计算刀头的点
            Face3d face4dt = new Face3d(dt2, dt3, dt4);
            Vector3 v4dt = u2 - b2;
            dt1 = Pus.Inters(face4dt, new Line(bdt1, bdt1 + v4dt));
            dt2 = Pus.Inters(face4dt, new Line(u3p, u3p + v4dt));
            dt3 = Pus.Inters(face4dt, new Line(b3, b3 + v4dt));
            dt4 = Pus.Inters(face4dt, new Line(b4, b4 + v4dt));

            Face3d face4buttom = new Face3d(b1, b2, b3);
            b5 = Pus.Inters(face4buttom, new Line(ii4, ii4 + v4dt));
            Vector3 bx = Pus.Inters(face4buttom, new Line(ii1, ii1 + v4dt));
            bdt1 = Pus.Inters(face4buttom, new Line(dt1, dt1 + v4dt));

            //平移所有点到下方
            Vector3 voff = new Vector3(0, -b * kscale - offset * 1.5, 0);
            Vector3 mk = Pus.OffsetXY(voff, k);
            Vector3 mi4 = Pus.OffsetXY(voff, i4);
            Vector3 mi3 = Pus.OffsetXY(voff, i3);
            Vector3 mi2 = Pus.OffsetXY(voff, i2);
            Vector3 mi1 = Pus.OffsetXY(voff, i1);
            Vector3 mdt1 = Pus.OffsetXY(voff, dt1);
            Vector3 mdt2 = Pus.OffsetXY(voff, dt2);
            Vector3 mdt3 = Pus.OffsetXY(voff, dt3);
            Vector3 mdt4 = Pus.OffsetXY(voff, dt4);
            Vector3 mii4 = Pus.OffsetXY(voff, ii4);
            Vector3 mii3 = Pus.OffsetXY(voff, ii3);
            Vector3 mii2 = Pus.OffsetXY(voff, ii2);
            Vector3 mii1 = Pus.OffsetXY(voff, ii1);

            Vector3 mb1 = Pus.OffsetXY(voff, b1);
            Vector3 mb2 = Pus.OffsetXY(voff, b2);
            Vector3 mb3 = Pus.OffsetXY(voff, b3);
            Vector3 mb4 = Pus.OffsetXY(voff, b4);
            Vector3 mb5 = Pus.OffsetXY(voff, b5);
            Vector3 mb6 = Pus.OffsetXY(voff, b6);
            Vector3 mbx = Pus.OffsetXY(voff, bx);
            Vector3 mbdt1 = Pus.OffsetXY(voff, bdt1);

            Vector3 mu1 = Pus.OffsetXY(voff, u1);
            Vector3 mu2 = Pus.OffsetXY(voff, u2);
            Vector3 mu3 = Pus.OffsetXY(voff, u3);
            Vector3 mu4 = Pus.OffsetXY(voff, u4);

            LwPolyline lshank = Pus.AddPointsToLwPolyLine(mb1, mu1, mu4, mb6);
            lshank.IsClosed = true;
            fun.PolyFill(dxf, lshank, lineWidth, contour);
            LwPolyline lshank_dt = Pus.AddPointsToLwPolyLine(mdt1, mu4);
            fun.PolyFill(dxf, lshank_dt, lineWidth, contour);
            LwPolyline lshank_dt1 = Pus.AddPointsToLwPolyLine(mdt2, mu3);
            fun.PolyFill(dxf, lshank_dt1, lineWidth, contour);

            LwPolyline lhead = Pus.AddPointsToLwPolyLine(mii4, mb5, mbdt1, mdt1);
            fun.PolyFill(dxf, lhead, lineWidth, contour);
            LwPolyline lhead1 = Pus.AddPointsToLwPolyLine(mbdt1, mb6);
            fun.PolyFill(dxf, lhead1, lineWidth, contour);
            LwPolyline lhead2 = Pus.AddPointsToLwPolyLine(mdt1, mi1);
            fun.PolyFill(dxf, lhead2, lineWidth, contour);
            LwPolyline lhead3 = Pus.AddPointsToLwPolyLine(mdt1, mbdt1);
            fun.PolyFill(dxf, lhead3, lineWidth, contour);
            LwPolyline lhead4 = Pus.AddPointsToLwPolyLine(mbx, mii1);
            fun.PolyFill(dxf, lhead4, lineWidth, contour);
            if (gamao > 0)
            {
                LwPolyline lheadu = Pus.AddPointsToLwPolyLine(mi1, mdt1, mdt2, mdt3, mdt4, mi3);
                fun.PolyFill(dxf, lheadu, lineWidth, contour);

                LwPolyline linsertu = Pus.AddPointsToLwPolyLine(mi4, mi1, mi2, mi3);
                linsertu.IsClosed = true;
                fun.PolyFill(dxf, linsertu, lineWidth, cutting);
            }

            LwPolyline linsertf = Pus.AddPointsToLwPolyLine(mi4, mii4, mii1, mi1);
            linsertf.IsClosed = true;
            fun.PolyFill(dxf, linsertf, lineWidth, cutting);
            //l视图标注
            LinearDimension dim_h1 = new LinearDimension(new Line(new Vector2(mk.X, mk.Y), new Vector2(mb5.X, mb5.Y)), offset * 0.5, Pus.Degree(b1, u1), dimensionStyle);
            fun.dxflinedim(dxf, dim_h1, h1);
            LinearDimension dim_h2 = new LinearDimension(new Line(new Vector2(mu1.X, mu1.Y), new Vector2(mb1.X, mb1.Y)), offset, Pus.Degree(u1, b1), dimensionStyle);
            fun.dxflinedim(dxf, dim_h2, h2);
            if (lambdas == 0)
                Pus.NeedleDim(dxf, new Line(new Vector2(mi4.X, mi4.Y), fun.Polar(new Vector2(mi4.X, mi4.Y), pi / 180, 1)), new Line(mi4, mi4 + mu4 - mu2), kscale * offset, "λs=0°", dimensionStyle);
            else
                Pus.NeedleDim(dxf, new Line(mi4, mi1), new Line(mi4, mi4 + mu4 - mu2), kscale * offset, "λs=" + Math.Round(lambdas * 180 / pi, 2) + "°", dimensionStyle);
            //左视图
            //所有点移动到原点
            //立正
            rotate = new Vector3(1, 0, 0);
            rotateAgl = pi / 2;
            Vector3 zi4 = Pus.Rodrigue(rotate, 1, rotateAgl, i4);
            Vector3 zi3 = Pus.Rodrigue(rotate, 1, rotateAgl, i3);
            Vector3 zi2 = Pus.Rodrigue(rotate, 1, rotateAgl, i2);
            Vector3 zi1 = Pus.Rodrigue(rotate, 1, rotateAgl, i1);
            Vector3 zdt1 = Pus.Rodrigue(rotate, 1, rotateAgl, dt1);
            Vector3 zdt2 = Pus.Rodrigue(rotate, 1, rotateAgl, dt2);
            Vector3 zdt3 = Pus.Rodrigue(rotate, 1, rotateAgl, dt3);
            Vector3 zdt4 = Pus.Rodrigue(rotate, 1, rotateAgl, dt4);

            Vector3 zii4 = Pus.Rodrigue(rotate, 1, rotateAgl, ii4);
            Vector3 zii3 = Pus.Rodrigue(rotate, 1, rotateAgl, ii3);
            Vector3 zii2 = Pus.Rodrigue(rotate, 1, rotateAgl, ii2);
            Vector3 zii1 = Pus.Rodrigue(rotate, 1, rotateAgl, ii1);

            Vector3 zb1 = Pus.Rodrigue(rotate, 1, rotateAgl, b1);
            Vector3 zb2 = Pus.Rodrigue(rotate, 1, rotateAgl, b2);
            Vector3 zb3 = Pus.Rodrigue(rotate, 1, rotateAgl, b3);
            Vector3 zb4 = Pus.Rodrigue(rotate, 1, rotateAgl, b4);
            Vector3 zb5 = Pus.Rodrigue(rotate, 1, rotateAgl, b5);
            Vector3 zb6 = Pus.Rodrigue(rotate, 1, rotateAgl, b6);
            Vector3 zbx = Pus.Rodrigue(rotate, 1, rotateAgl, bx);
            Vector3 zbdt1 = Pus.Rodrigue(rotate, 1, rotateAgl, bdt1);

            Vector3 zu1 = Pus.Rodrigue(rotate, 1, rotateAgl, u1);
            Vector3 zu2 = Pus.Rodrigue(rotate, 1, rotateAgl, u2);
            Vector3 zu3 = Pus.Rodrigue(rotate, 1, rotateAgl, u3);
            Vector3 zu4 = Pus.Rodrigue(rotate, 1, rotateAgl, u4);

            //绕y转，露出左面
            rotate = new Vector3(0, 1, 0);
            rotateAgl = pi / 2;
            zi4 = Pus.Rodrigue(rotate, 1, rotateAgl, zi4);
            zi3 = Pus.Rodrigue(rotate, 1, rotateAgl, zi3);
            zi2 = Pus.Rodrigue(rotate, 1, rotateAgl, zi2);
            zi1 = Pus.Rodrigue(rotate, 1, rotateAgl, zi1);
            zdt1 = Pus.Rodrigue(rotate, 1, rotateAgl, zdt1);
            zdt2 = Pus.Rodrigue(rotate, 1, rotateAgl, zdt2);
            zdt3 = Pus.Rodrigue(rotate, 1, rotateAgl, zdt3);
            zdt4 = Pus.Rodrigue(rotate, 1, rotateAgl, zdt4);

            zii4 = Pus.Rodrigue(rotate, 1, rotateAgl, zii4);
            zii3 = Pus.Rodrigue(rotate, 1, rotateAgl, zii3);
            zii2 = Pus.Rodrigue(rotate, 1, rotateAgl, zii2);
            zii1 = Pus.Rodrigue(rotate, 1, rotateAgl, zii1);

            zb1 = Pus.Rodrigue(rotate, 1, rotateAgl, zb1);
            zb2 = Pus.Rodrigue(rotate, 1, rotateAgl, zb2);
            zb3 = Pus.Rodrigue(rotate, 1, rotateAgl, zb3);
            zb4 = Pus.Rodrigue(rotate, 1, rotateAgl, zb4);
            zb5 = Pus.Rodrigue(rotate, 1, rotateAgl, zb5);
            zb6 = Pus.Rodrigue(rotate, 1, rotateAgl, zb6);
            zbx = Pus.Rodrigue(rotate, 1, rotateAgl, zbx);
            zbdt1 = Pus.Rodrigue(rotate, 1, rotateAgl, zbdt1);

            zu1 = Pus.Rodrigue(rotate, 1, rotateAgl, zu1);
            zu2 = Pus.Rodrigue(rotate, 1, rotateAgl, zu2);
            zu3 = Pus.Rodrigue(rotate, 1, rotateAgl, zu3);
            zu4 = Pus.Rodrigue(rotate, 1, rotateAgl, zu4);

            //平移
            voff = new Vector3(-b * kscale - offset * 2, 0, 0);
            zi4 = Pus.OffsetXY(voff, zi4);
            zi3 = Pus.OffsetXY(voff, zi3);
            zi2 = Pus.OffsetXY(voff, zi2);
            zi1 = Pus.OffsetXY(voff, zi1);
            zdt1 = Pus.OffsetXY(voff, zdt1);
            zdt2 = Pus.OffsetXY(voff, zdt2);
            zdt3 = Pus.OffsetXY(voff, zdt3);
            zdt4 = Pus.OffsetXY(voff, zdt4);

            zii4 = Pus.OffsetXY(voff, zii4);
            zii3 = Pus.OffsetXY(voff, zii3);
            zii2 = Pus.OffsetXY(voff, zii2);
            zii1 = Pus.OffsetXY(voff, zii1);

            zb1 = Pus.OffsetXY(voff, zb1);
            zb2 = Pus.OffsetXY(voff, zb2);
            zb3 = Pus.OffsetXY(voff, zb3);
            zb4 = Pus.OffsetXY(voff, zb4);
            zb5 = Pus.OffsetXY(voff, zb5);
            zb6 = Pus.OffsetXY(voff, zb6);
            zbx = Pus.OffsetXY(voff, zbx);
            zbdt1 = Pus.OffsetXY(voff, zbdt1);

            zu1 = Pus.OffsetXY(voff, zu1);
            zu2 = Pus.OffsetXY(voff, zu2);
            zu3 = Pus.OffsetXY(voff, zu3);
            zu4 = Pus.OffsetXY(voff, zu4);

            //左视图绘制
            LwPolyline zshank = Pus.AddPointsToLwPolyLine(zii4, zb5, zb4, zb3, zdt3, zdt4, zi3);
            fun.PolyFill(dxf, zshank, lineWidth, contour);
            LwPolyline zshank2 = Pus.AddPointsToLwPolyLine(zb4, zdt4);
            fun.PolyFill(dxf, zshank2, lineWidth, contour);
            if (lambdas > 0)
            {
                LwPolyline zshank1 = Pus.AddPointsToLwPolyLine(zdt3, zdt2, zdt1, zi1);
                fun.PolyFill(dxf, zshank1, lineWidth, contour);

                LwPolyline zinsert = Pus.AddPointsToLwPolyLine(zi4, zi1, zi2, zi3);
                zinsert.IsClosed = true;
                fun.PolyFill(dxf, zinsert, lineWidth, cutting);
            }

            LwPolyline zlen1 = Pus.AddPointsToLwPolyLine(zi3, zii3, zii4, zi4);
            zlen1.IsClosed = true;
            fun.PolyFill(dxf, zlen1, lineWidth, cutting);

            if (cutagl < pi / 2)
            {
                LwPolyline zlen2 = Pus.AddPointsToLwPolyLine(zii4, zii1, zi1, zi4);
                fun.PolyFill(dxf, zlen2, lineWidth, cutting);
            }
            //if (zdt1.Y > zu4.Y)
            //{
            //    Vector2 visible = Pus.IntersOnP(zi4, zi1, zb4, zu4);
            //    LwPolyline visiLine = Pus.AddPointsToLwPolyLine(zdt1, zu4);
            //    Pus.AddPointsToLwPolyLine(visiLine, visible);
            //    fun.PolyFill(dxf, visiLine, lineWidth, contour);
            //}
            //左视图标注
            //刃倾角
            if (gamao == 0)
                Pus.NeedleDim(dxf, new Line(new Vector2(zi4.X, zi4.Y), fun.Polar(new Vector2(zi4.X, zi4.Y), Pus.AngleOnP(zi3, zi4) + pi / 180, 1)), new Line(zi3, zi4), offset * 1.5, "γo=0°", dimensionStyle);
            else
                Pus.NeedleDim(dxf, new Line(zi3, zi4), new Line(new Vector2(zi4.X, zi4.Y), fun.Polar(new Vector2(zi4.X, zi4.Y), Pus.AngleOnP(zi3, zi4) + gamao, 1)), offset * 1.5, "γo=" + Math.Round(lambdas * 180 / pi, 2) + "°", dimensionStyle);

            //LinearDimension dim_s = new LinearDimension(new Line(zi4, zii4), offset, Pus.Degree(zi4, zi3) + 90, dimensionStyle);
            //fun.dxflinedim(dxf, dim_s, s);

            //后角
            if (alphan == 0)
                Pus.NeedleDim(dxf, new Line(zi4, zii4), new Line(new Vector2(zi4.X, zi4.Y), fun.Polar(new Vector2(zi4.X, zi4.Y), Pus.AngleOnP(zi4, zii4) + pi / 180, 1)), offset + h1 * kscale, "αn=0°", dimensionStyle);
            else
                Pus.NeedleDim(dxf, new Line(zi4, zii4), new Line(new Vector2(zi4.X, zi4.Y), fun.Polar(new Vector2(zi4.X, zi4.Y), Pus.AngleOnP(zi4, zii4) + alphan, 1)), offset + h1 * kscale, "αn=" + Math.Round(alphan * 180 / pi, 2) + "°", dimensionStyle);
            //图框
            if (Convert.ToDouble(data["isframe"]) == 1)
            {
                Vector2 c4c = new Vector2((b2.X + zb3.X) / 2, (b2.Y + mu1.Y) / 2);
                Dictionary<string, Vector2> positions = Frame.frameA3X(dxf, new Vector2(c4c.X - 420 / 2, c4c.Y + 297 / 2), new Dictionary<string, object>());
                fun.writetextofC(dxf, kscale + ":1", positions["比例"], 3.5, 0, 0.6, 3);
            }

            dxf.DrawingVariables.AcadVer = DxfVersion.AutoCad2007;
            dxf.Save(path);
        }*/

        //R型刀头 横小
        public static void StyleR_InsertS(Dictionary<string, Object> data)
        {
            DxfDocument dxf = new DxfDocument();

            #region 图层

            Layer contour = fun.SetLayer("contour");//轮廓层
            Layer dimensioning = fun.SetLayer("dimensioning");//尺寸层
            Layer refin = fun.SetLayer("refin");//基准线/内轮廓/虚线
            Layer center = fun.SetLayer("center");//中心线
            Layer textlayer = fun.SetLayer("textlayer");//文本层
            Layer hatching = fun.SetLayer("hatching");//填充层
            Layer additionalline = fun.SetLayer("additionalline");//附加线
            Layer cutting = fun.SetLayer("cutting");//切削层

            #endregion

            #region 变量

            string path = Convert.ToString(data["path"]);

            double h1 = 28.49;
            double b = 28.2;
            double l3 = 18;
            double a = 4.64;
            double f = 27.9;
            double h2 = 27.79;
            double l1 = 159.5;
            double l2 = 51.09;
            double s = 6.66;
            double r = 1;

            double scale = 1;
            //double scale = Convert.ToDouble(data["scale"]);
            //double h1 = Convert.ToDouble(data["hf"]) * scale;
            //double b = Convert.ToDouble(data["b"]) * scale;
            //double l3 = Convert.ToDouble(data["l3"]) * scale;
            //double a = Convert.ToDouble(data["a"]) * scale;
            //double f = Convert.ToDouble(data["wf"]) * scale;
            //double h2 = Convert.ToDouble(data["h"]) * scale;
            //double l1 = Convert.ToDouble(data["lf"]) * scale;
            //double l2 = Convert.ToDouble(data["lh"]) * scale;
            //double s = Convert.ToDouble(data["s"]) * scale;
            //double r = Convert.ToDouble(data["re"]) * scale;

            double bs = b / 28.2;//b缩放
            double l2s = l2 / 51.09;//l2缩放
            double h2s = h2 / 27.79;//h2缩放

            double rad = Math.PI / 180;
            double offset = 10;
            double textHeight = 3.5;


            #endregion

            #region 点

            //右
            Vector2 v0 = new Vector2(0, 0);
            Vector2 v1 = new Vector2(0, l1 / 2);
            Vector2 v2 = Vector2.Polar(v1, b, 0);
            Vector2 v3 = Vector2.Polar(v2, 17.35 * h2s, -90 * rad);
            Vector2 v4 = Vector2.Polar(v3, h2, -90 * rad);
            Vector2 v5 = Vector2.Polar(v2, l1 / 2, -90 * rad);
            Vector2 v9 = new Vector2(v1.X + f, v1.Y - l1);
            Vector2 v6 = new Vector2(v1.X + b, v9.Y + l2);
            Vector2 v8 = new Vector2(v9.X + a, v9.Y + l3 * Math.Cos(15 * rad));
            Vector2 v7 = Vector2.Polar(Vector2.Polar(v8, r, 165 * rad), 29.62 * l2s, 90 * rad);
            Vector2 v10 = fun.Polar2(v9, l3, 90 + 75);
            Vector2 v11 = Vector2.Polar(v9, l3 / Math.Sin(45 * rad), 120 * rad);
            Vector2 v13 = Vector2.Polar(v6, b, 180 * rad);
            Vector2 v12 = Vector2.Polar(v13, 42.76 * l2s, -90 * rad);
            Vector2 v14 = Vector2.Polar(v5, b, 180 * rad);
            Vector2 v15 = Vector2.Polar(v4, b, 180 * rad);
            Vector2 v16 = Vector2.Polar(v3, b, 180 * rad);

            Vector2 vc1 = Vector2.Polar((v8 + v9) / 2, b * 1.5, (90 + 75) * rad);
            Vector2 vc2 = Vector2.Polar((v8 + v9) / 2, offset * 1.5, -15 * rad);
            Vector2 vc3 = Vector2.Polar((v9 + v10) / 2, offset, -105 * rad);
            Vector2 vc4 = Vector2.Polar((v9 + v10) / 2, b * 2, 75 * rad);

            //左1
            Vector2 v17 = Vector2.Polar(v1, 42.48 * bs, (180 + 36) * rad);
            Vector2 v18 = Vector2.Polar(v17, 11.14 * bs, 164 * rad);
            Vector2 v19 = Vector2.Polar(v18, s, 164 * rad);
            Vector2 v20 = Vector2.Polar(v19, 17.72 * bs, 74 * rad);
            Vector2 v21 = Vector2.Polar(v18, 17.72 * bs, 74 * rad);
            Vector2 v22 = Vector2.Polar(v19, 30.3 * bs, 74 * rad);

            Vector2 v23 = Vector2.Polar(v19, s * 2, 180 * rad);
            Vector2 v24 = Vector2.Polar(v23, 10.52 * bs, 180 * rad);
            Vector2 v25 = Vector2.Polar(v24, 7.37 * bs, 180 * rad);
            Vector2 v26 = Vector2.Polar(v25, 17.99 * bs, 75 * rad);
            Vector2 v27 = Vector2.Polar(v24, 14.54 * bs, 75 * rad);
            Vector2 v28 = Vector2.Polar(v25, 30.67 * bs, 75 * rad);

            //左2
            Vector2 v29 = Vector2.Polar(v1, 100.69 * bs, (180 + 62) * rad);
            Vector2 v30 = Vector2.Polar(v29, 6.68 * bs, (180 + 68) * rad);
            Vector2 v31 = Vector2.Polar(v30, 17.65 * bs, (180 - 15) * rad);
            Vector2 v32 = Vector2.Polar(v29, 20.02 * bs, (180 - 15) * rad);
            Vector2 v33 = Vector2.Polar(v29, h1, (180 + 68) * rad);
            Vector2 v34 = Vector2.Polar(v33, 27.16 * bs, (180 - 15) * rad);
            Vector2 v35 = Vector2.Polar(v29, 30.89 * bs, (180 - 15) * rad);

            //左3
            Vector2 v36 = Vector2.Polar(v1, 157.08 * bs, -108 * rad);
            Vector2 v37 = Vector2.Polar(v36, 6.94 * bs, -113 * rad);
            Vector2 v38 = Vector2.Polar(v37, 18.12 * bs, (180 - 21) * rad);
            Vector2 v39 = Vector2.Polar(v36, 18.12 * bs, (180 - 21) * rad);
            Vector2 v40 = Vector2.Polar(v36, h1, -113 * rad);
            Vector2 v41 = Vector2.Polar(v40, 28.09 * bs, (180 - 15) * rad);
            Vector2 v42 = Vector2.Polar(v36, 31.45 * bs, (180 - 21) * rad);

            //左4
            Vector2 v43 = Vector2.Polar(v1, 213.44 * bs, -103 * rad);
            Vector2 v44 = Vector2.Polar(v43, 6.83 * bs, -113 * rad);
            Vector2 v45 = Vector2.Polar(v44, 18.1 * bs, (180 - 9) * rad);
            Vector2 v46 = Vector2.Polar(v43, 21.23 * bs, (180 - 9) * rad);
            Vector2 v47 = Vector2.Polar(v43, h1, -113 * rad);
            Vector2 v48 = Vector2.Polar(v47, 28.45 * bs, (180 - 15) * rad);
            Vector2 v49 = Vector2.Polar(v43, 30.86 * bs, (180 - 9) * rad);

            #endregion

            #region 线

            //右
            Line lc01 = new Line(vc1, vc2);
            Line lc02 = new Line(vc3, vc4);
            Line line01 = new Line(v6, v13);
            LwPolyline lw01 = Pus.AddPointsToLwPolyLine(Vector2.Polar(Vector2.Polar(v9, l3, 165 * rad), r, 75 * rad), v12, v13, v14, v15, v16, v1, v2, v3, v4, v5, v6, v7, Vector2.Polar(v8, r, 165 * rad));
            LwPolyline lw02 = Pus.AddPointsToLwPolyLine(v3, v4, v15, v16, v3);
            LwPolyline lw03 = Pus.AddPointsToLwPolyLine(fun.Polar2(v9, 13 / 2, 75), v9, v10, v11, v8, fun.Polar2(v9, 13 / 2, 75));

            lw03 = Pus.Fillet4LwPline(lw03, 1, r);
            lw03 = Pus.Fillet4LwPline(lw03, 3, r);
            lw03 = Pus.Fillet4LwPline(lw03, 5, r);
            lw03 = Pus.Fillet4LwPline(lw03, 7, r);

            fun.AddHatch(dxf, hatching, lw02, new Line[32], new Arc[32], 45, 10);

            //左1
            LwPolyline lw11 = Pus.AddPointsToLwPolyLine(v18, v19, v20, v21, v18);
            LwPolyline lw12 = Pus.AddPointsToLwPolyLine(v17, v22, v20, v21, v18, v17);
            lw12.Vertexes[0].Bulge = Math.Tan(60 * rad / 4);

            LwPolyline lw13 = Pus.AddPointsToLwPolyLine(v24, v25, v26, v27, v24);
            LwPolyline lw14 = Pus.AddPointsToLwPolyLine(v23, v28, v26, v27, v24, v23);
            lw14.Vertexes[0].Bulge = Math.Tan(60 * rad / 4);

            fun.AddHatch(dxf, hatching, lw11, new Line[32], new Arc[32], 45, 10);
            fun.AddHatch(dxf, hatching, lw12, new Line[32], new Arc[32], -45, 10);
            fun.AddHatch(dxf, hatching, lw13, new Line[32], new Arc[32], 45, 10);
            fun.AddHatch(dxf, hatching, lw14, new Line[32], new Arc[32], -45, 10);

            //左2
            LwPolyline lw21 = Pus.AddPointsToLwPolyLine(v29, v30, v31, v32, v29);
            LwPolyline lw22 = Pus.AddPointsToLwPolyLine(v35, v34, v33, v30, v31, v32, v35);
            lw22.Vertexes[0].Bulge = Math.Tan(60 * rad / 4);

            fun.AddHatch(dxf, hatching, lw21, new Line[32], new Arc[32], 45, 10);
            fun.AddHatch(dxf, hatching, lw22, new Line[32], new Arc[32], -45, 10);

            //左3
            LwPolyline lw31 = Pus.AddPointsToLwPolyLine(v36, v37, v38, v39, v36);
            LwPolyline lw32 = Pus.AddPointsToLwPolyLine(v42, v41, v40, v37, v38, v39, v42);
            lw32.Vertexes[0].Bulge = Math.Tan(60 * rad / 4);

            fun.AddHatch(dxf, hatching, lw31, new Line[32], new Arc[32], 45, 10);
            fun.AddHatch(dxf, hatching, lw32, new Line[32], new Arc[32], -45, 10);

            //左4
            LwPolyline lw41 = Pus.AddPointsToLwPolyLine(v43, v44, v45, v46, v43);
            LwPolyline lw42 = Pus.AddPointsToLwPolyLine(v49, v48, v47, v44, v45, v46, v49);
            lw42.Vertexes[0].Bulge = Math.Tan(60 * rad / 4);

            fun.AddHatch(dxf, hatching, lw41, new Line[32], new Arc[32], 45, 10);
            fun.AddHatch(dxf, hatching, lw42, new Line[32], new Arc[32], -45, 10);

            #endregion

            #region 标注

            //右
            fun.DimensionLiner(dxf, dimensioning, v1, v2, offset, 0, "b");
            fun.DimensionLiner(dxf, dimensioning, v3, v4, offset, -90, "h2");
            fun.DimensionLiner(dxf, dimensioning, v2, v9, offset * 3, -90, "l1");
            fun.DimensionLiner(dxf, dimensioning, v6, v9, offset * 2, -90, "l2");
            fun.DimensionLiner(dxf, dimensioning, v8, v9, -(((v8 - v9) / 2).Y + offset * 2), 0, "a");
            fun.DimensionLiner(dxf, dimensioning, v9, v12, ((v12 - v9) / 2).Y + offset * 2, 180, "f");
            fun.DimensionAligned(dxf, dimensioning, v8, v11, offset, "l3");
            fun.DimensionAngular(dxf, dimensioning, new Line(v9, fun.Polar2(v9, r, 0)), new Line(v9, v8), offset, "75°±1°");
            fun.DimensionRadius(dxf, dimensioning, fun.DrawArc4(fun.Polar2(v9, r, 75), r, fun.Polar2(v9, r, 165), 0), 135, offset, "r");

            fun.jt(dxf, vc1, -105, offset * 0.5, textHeight, "B");
            fun.jt(dxf, vc2, -105, offset * 0.5, textHeight, "B");
            fun.jt(dxf, vc3, -15, offset * 0.5, 1, "A");
            fun.jt(dxf, vc4, -15, offset * 0.5, 1, "A");

            //左1
            fun.DimensionAligned(dxf, dimensioning, v18, v19, -offset, "s");
            fun.DimensionLiner(dxf, dimensioning, v24, v25, -offset, -15, "s");
            fun.DimensionAngular(dxf, dimensioning, new Line(v19, fun.PointRotate(v19, fun.Polar2(v19, r, 74), 6 * rad)), new Line(v19, v22), b + offset, "-6°±1°");
            fun.DimensionAngular(dxf, dimensioning, new Line(v25, fun.PointRotate(v25, fun.Polar2(v25, r, 75), 1 * rad)), new Line(v25, v28), b + offset, "0°±1°");

            Text text1 = new Text("A-A", fun.Polar2((v28 + v22) / 2, offset * 2, 90), textHeight, 0);

            //左2
            fun.DimensionLiner(dxf, dimensioning, v29, v33, -offset * 2, 75, "h1");
            fun.DimensionAngular(dxf, dimensioning, new Line(v29, fun.PointRotate(v29, fun.Polar2(v29, r, -15), 1 * rad)), new Line(v29, fun.Polar2(v29, r, -15)), offset, "0°±1°");

            Text text2 = new Text("B-B", fun.Polar2(v32, offset * 2, 90), textHeight, 0);

            //左3
            fun.DimensionLiner(dxf, dimensioning, v36, v40, -offset * 2, 69, "h1");
            fun.DimensionAngular(dxf, dimensioning, new Line(v36, fun.PointRotate(v36, fun.Polar2(v36, r, -21), 6 * rad)), new Line(v36, fun.Polar2(v36, r, -21)), offset, "-6°±1°");

            //左4

            fun.DimensionLiner(dxf, dimensioning, v43, v47, -offset * 2, 76, "h1");
            fun.DimensionAngular(dxf, dimensioning, new Line(v43, fun.PointRotate(v43, fun.Polar2(v43, r, -9), 5 * rad)), new Line(v43, fun.Polar2(v43, r, -9)), offset, "5°±1°");
            #endregion

            #region 图框

            double isframe = Convert.ToInt32(data["isframe"]);
            String isframe_chose = Convert.ToString(data["isframe_chose"]);
            Vector2 p0 = new Vector2(0, 0);


            if (isframe == 1)
            {
                if (isframe_chose.Equals("0"))
                {
                    Dictionary<string, Vector2> position = Frame.frameA0X(dxf, new Vector2(p0.X - 1189 / 2.0, p0.Y + 841 / 2.0), data);
                    fun.writetext(dxf, scale + ":1", position["比例"], 3.5, 0, 0.6, "C");
                }

                if (isframe_chose.Equals("1"))
                {
                    Dictionary<string, Vector2> position = Frame.frameA1X(dxf, new Vector2(p0.X - 841 / 2.0, p0.Y + 594 / 2.0), data);
                    fun.writetext(dxf, scale + ":1", position["比例"], 3.5, 0, 0.6, "C");
                }

                if (isframe_chose.Equals("2"))
                {
                    Dictionary<string, Vector2> position = Frame.frameA2X(dxf, new Vector2(p0.X - 594 / 2.0, p0.Y + 420 / 2.0), data);
                    fun.writetext(dxf, scale + ":1", position["比例"], 3.5, 0, 0.6, "C");
                }

                if (isframe_chose.Equals("3"))
                {
                    Dictionary<string, Vector2> position = Frame.frameA3X(dxf, new Vector2(p0.X - 420 / 2.0, p0.Y + 297 / 2.0), data);
                    fun.writetext(dxf, scale + ":1", position["比例"], 3.5, 0, 0.6, "C");
                }

                if (isframe_chose.Equals("4X"))
                {
                    Dictionary<string, Vector2> position = Frame.frameA4X(dxf, new Vector2(p0.X - 297 / 2.0, p0.Y + 210 / 2.0 - 10 * 2.26), data);
                    fun.writetext(dxf, scale + ":1", position["比例"], 3.5, 0, 0.6, "C");
                }

                if (isframe_chose.Equals("4Y"))
                {
                    Dictionary<string, Vector2> position = Frame.frameA4Y(dxf, new Vector2(p0.X - 210 / 2.0, p0.Y + 297 / 2.0), data);
                    fun.writetext(dxf, scale + ":1", position["比例"], 3.5, 0, 0.6, "C");
                }
            }

            #endregion

            #region 编辑

            //添加到实体并设置图层
            fun.AddEntities(dxf, contour, line01, lw01, lw02, lw03, lw11, lw12, lw13, lw14, lw21, lw22, lw31, lw32, lw41, lw42);
            fun.AddEntities(dxf, center, lc01, lc02);
            fun.AddEntities(dxf, textlayer, text1, text2);



            //设置跟随图层
            fun.SetByLayer(dxf);

            #endregion

            dxf.DrawingVariables.AcadVer = DxfVersion.AutoCad2007;
            dxf.Save(path);
        }


        //S型刀头 纵小
        /*        public static void StyleS_InsertC(Dictionary<string, Object> data)
                {
                    DxfDocument dxf = new DxfDocument();
                    Layer contour = new Layer("contour") { Color = AciColor.Cyan };    //1,轮廓层
                    Layer cutting = new Layer("cutting") { Color = AciColor.Red };    //切削层

                    string path = Convert.ToString(data["path"]);
                    //参数名称取自ISO 5610-2
                    double b = 8;
                    double l1 = 60;
                    double l2 = 12;
                    double f = 10;
                    double insertAngle = 80 * pi / 180;
                    double l3 = 6.4;
                    double h2 = 8;
                    double h1 = 8;
                    double s = 2.38;
                    double alphan = 7 * pi / 180;
                    double holder_agl = 45 * pi / 180;
                    double lambdas = 0;
                    double gamao = 0;
                    double repsilon = 0;
                    #region 13399中的参数名称与之对应
                    try
                    {
                        if (data["re"] != null)
                            repsilon = Convert.ToDouble(data["re"]);
                    }
                    catch (KeyNotFoundException) { }
                    try
                    {
                        if (data["lams"] != null)
                            lambdas = Convert.ToDouble(data["lams"]) * pi / 180;
                    }
                    catch (KeyNotFoundException) { }
                    try
                    {
                        if (data["gamo"] != null)
                            gamao = Convert.ToDouble(data["gamo"]) * pi / 180;
                    }
                    catch (KeyNotFoundException) { }
                    try
                    {
                        if (data["b"] != null)
                            b = Convert.ToDouble(data["b"]);
                    }
                    catch (KeyNotFoundException) { }
                    try
                    {
                        if (data["s"] != null)
                            s = Convert.ToDouble(data["s"]);
                    }
                    catch (KeyNotFoundException) { }
                    try
                    {
                        if (data["l"] != null)
                            l3 = Convert.ToDouble(data["l"]);
                    }
                    catch (KeyNotFoundException) { }
                    try
                    {
                        if (data["lf"] != null)
                            l1 = Convert.ToDouble(data["lf"]);
                    }
                    catch (KeyNotFoundException) { }
                    try
                    {
                        if (data["lh"] != null)
                            l2 = Convert.ToDouble(data["lh"]);
                    }
                    catch (KeyNotFoundException) { }
                    try
                    {
                        if (data["wf"] != null)
                            f = Convert.ToDouble(data["wf"]);
                    }
                    catch (KeyNotFoundException) { }
                    try
                    {
                        if (data["h"] != null)
                            h2 = Convert.ToDouble(data["h"]);
                    }
                    catch (KeyNotFoundException) { }
                    try
                    {
                        if (data["hf"] != null)
                            h1 = Convert.ToDouble(data["hf"]);
                    }
                    catch (KeyNotFoundException) { }
                    try
                    {
                        if (data["epsr"] != null)
                            insertAngle = Convert.ToDouble(data["epsr"]) * pi / 180;
                    }
                    catch (KeyNotFoundException) { }
                    try
                    {
                        if (data["kapr"] != null)
                            holder_agl = Convert.ToDouble(data["kapr"]) * pi / 180;
                    }
                    catch (KeyNotFoundException) { }
                    try
                    {
                        if (data["an"] != null)
                            alphan = Convert.ToDouble(data["an"]) * pi / 180;
                    }
                    catch (KeyNotFoundException) { }
                    Dictionary<double, double> l3_repsilon = new Dictionary<double, double> {
                                { 6.4,0.4},
                                { 9.525,0.8},
                                { 12.7,0.8},
                                { 15.875,1.2},
                                { 19.05,1.2},
                                { 25.4,2.4},
                            };
                    #endregion
                    //俯视图
                    Vector2 c0 = new Vector2(0, 0);
                    Vector2 c1 = c0;
                    Vector2 c2 = new Vector2(c1.X, c1.Y + b);
                    Vector2 c3 = new Vector2(c2.X - l1 + l2, c2.Y);
                    Vector2 c5 = new Vector2(c3.X, c1.Y);
                    Vector2 i4 = new Vector2(c1.X - l1, c3.Y - f);
                    Vector2[] insertContourPoints = DiamondPoints(i4, l3, insertAngle, false, holder_agl);
                    Vector2 i1 = insertContourPoints[1];
                    Vector2 i2 = insertContourPoints[2];
                    Vector2 i3 = insertContourPoints[3];
                    //先画刀片
                    LwPolyline insertContour = AddPointsToLwPolyLine(insertContourPoints);
                    insertContour.IsClosed = true;
                    //为四个角添加圆弧
                    int index = 0;
                    for (int i = 1; i <= 4; i++)
                    {
                        AglToArc(insertContour, index, repsilon, true);
                        index = index + 2;
                    }
                    DrawPlineByTwoPoints(dxf, c3, c5, contour);
                    fun.PolyFill(dxf, insertContour, 0.1, cutting);
                    //little
                    Vector2 little1 = insertContour.Vertexes[2].Position;
                    Vector2 little2 = insertContour.Vertexes[3].Position;
                    LwPolyline littleAgl = AddPointsToLwPolyLine(little1, i1, little2);
                    fun.PolyFill(dxf, littleAgl, 0.1, contour);
                    //偏移后的刀片底部外轮廓
                    double inset_offset = s * Math.Tan(alphan);
                    Vector2[] buttom_points = OffsetPoints(inset_offset, insertContourPoints);
                    Vector2 ii4 = buttom_points[0];
                    Vector2 ii1 = buttom_points[1];
                    Vector2 ii2 = buttom_points[2];
                    Vector2 ii3 = buttom_points[3];
                    //刀片底面的轮廓由顶面轮廓偏移而得
                    //LwPolyline buttom = AddPointsToLwPolyLine(buttom_points);
                    //buttom.IsClosed = true;
                    //fun.PolyFill(dxf, buttom, 0.1, cutting);
                    //外轮廓
                    Vector2 x1;
                    Arc iarc1 = GetArcFromPline(insertContour, 1);
                    List<Vector2> xpoints1 = LineXArc(iarc1, ii4, ii3);
                    if (xpoints1 == null || xpoints1.Count == 0)
                        x1 = fun.Inters(ii4, ii3, i1, i4);
                    else if (xpoints1.Count == 1)
                        x1 = xpoints1[0];
                    else
                        x1 = xpoints1[1];
                    Vector2 c6 = new Vector2(c5.X - 2, x1.Y);
                    Vector2 x2;
                    Arc iarc3 = GetArcFromPline(insertContour, 3);
                    List<Vector2> xpoints2 = LineXArc(iarc3, ii2, ii3);
                    if (xpoints2 == null || xpoints2.Count == 0)
                        x2 = fun.Inters(ii2, ii3, i1, i2);
                    else if (xpoints2.Count == 1)
                        x2 = xpoints2[0];
                    else
                        x2 = xpoints2[1];
                    Vector2 c4 = fun.Inters(ii2, ii3, c2, c3);
                    LwPolyline pline = AddPointsToLwPolyLine(x1, c6, c5, c1, c2, c3, c4, x2);
                    fun.PolyFill(dxf, pline, 0.1, contour);
                    DrawPlineByTwoPoints(dxf, c3, c5);
                    DimensionStyle dimensionStyle = fun.CreateDimStyle();
                    dimensionStyle.ArrowSize = 0.2;
                    dimensionStyle.DimArrow1 = DimensionArrowhead.Closedfilled;
                    dimensionStyle.DimArrow2 = DimensionArrowhead.Closedfilled;
                    dimensionStyle.TextHeight = 0.5;
                    double offset = 7;
                    LinearDimension dim_l1 = new LinearDimension(new Line(i4, c1), 1.5 * offset, -180, dimensionStyle);
                    fun.dxflinedim(dxf, dim_l1, l1);
                    LinearDimension dim_l2 = new LinearDimension(new Line(i4, c5), 1.3 * offset, -180, dimensionStyle);
                    fun.dxflinedim(dxf, dim_l2, l2);
                    LinearDimension dim_b = new LinearDimension(new Line(c2, c1), offset, -90, dimensionStyle);
                    fun.dxflinedim(dxf, dim_b, b);
                    LinearDimension dim_f = new LinearDimension(new Line(i4, c4), offset, 90, dimensionStyle);
                    fun.dxflinedim(dxf, dim_f, f);
                    LinearDimension dim_l3 = new LinearDimension(new Line(i3, i2), offset, (pi - insertAngle - holder_agl) * 180 / pi, dimensionStyle);
                    fun.dxflinedim(dxf, dim_l3, l3);
                    Angular2LineDimension dim_insertAgl = new Angular2LineDimension(new Line(i4, i1), new Line(i4, i3), 1);
                    dim_insertAgl.UserText = insertAngle * 180 / pi + "°";
                    dim_insertAgl.Style = dimensionStyle;
                    dim_insertAgl.SetDimensionLinePosition(new Vector2(i4.X, i4.Y + 2));
                    dxf.AddEntity(dim_insertAgl);
                    Angular2LineDimension dim_style = new Angular2LineDimension(new Line(i4, new Vector2(i4.X - 1, i4.Y)), new Line(i4, i3), 1);
                    dim_style.UserText = holder_agl * 180 / pi + "°";
                    dim_style.Style = dimensionStyle;
                    dim_style.SetDimensionLinePosition(new Vector2(i4.X - 2, i4.Y + 2));
                    dxf.AddEntity(dim_style);
                    //刀尖圆弧半径标注
                    RadialDimension dim_repsilon = ReDimension(insertContour, 2, dimensionStyle);
                    dim_repsilon.SetDimensionLinePosition(new Vector2(i1.X + 1, i1.Y + 0.5));
                    dim_repsilon.UserText = "rε=" + repsilon;
                    dxf.AddEntity(dim_repsilon);
                    //主视图
                    //第二后面与第二副后面交线在主视图上投影与y轴夹角的正切值
                    //double k = Math.Pow(Math.Tan(holder_agl), 2) + Math.Tan(holder_agl);
                    Vector2 m1 = new Vector2(c1.X, c2.Y + offset);
                    Vector2 m2 = new Vector2(m1.X, m1.Y + h2);
                    Vector2 m3 = new Vector2(c5.X, m2.Y);
                    //刀片上第二个弧的结束点的x坐标小于x1的坐标
                    Vector2 m4 = new Vector2(x1.X, m1.Y + h1);
                    Vector2 m5 = new Vector2(i3.X, m4.Y);
                    Vector2 m6 = new Vector2(ii3.X, m5.Y - s);
                    Vector2 m7 = new Vector2(ii4.X, m4.Y - s);
                    Vector2 m8 = new Vector2(m6.X, m1.Y);
                    Vector2 m9 = new Vector2(m7.X, m1.Y);
                    Vector2 m10 = new Vector2(c6.X, m1.Y);
                    Vector2 m11 = new Vector2(m3.X, m1.Y);
                    Vector2 m12 = new Vector2(c6.X, m2.Y);
                    Vector2 m13 = new Vector2(i4.X, m4.Y);
                    LwPolyline polylineM = AddPointsToLwPolyLine(m6, m8, m1, m2, m4, m7);
                    fun.PolyFill(dxf, polylineM, 0.1, contour);
                    LwPolyline insertM = AddPointsToLwPolyLine(m4, m5, m6, m7);
                    fun.PolyFill(dxf, insertM, 0.1, cutting);
                    DrawPlineByTwoPoints(dxf, m3, m11);
                    DrawPlineByTwoPoints(dxf, m12, m10);
                    DrawPlineByTwoPoints(dxf, m13, m7, cutting);
                    DrawPlineByTwoPoints(dxf, m9, m7);
                    //主视图标注
                    LinearDimension dim_h2 = new LinearDimension(new Line(m1, m2), offset, -90, dimensionStyle);
                    fun.dxflinedim(dxf, dim_h2, h2);
                    LinearDimension dim_h1 = new LinearDimension(new Line(m5, m8), offset * 1.5, 90, dimensionStyle);
                    fun.dxflinedim(dxf, dim_h1, h1);
                    LinearDimension dim_s = new LinearDimension(new Line(m5, m6), offset * 0.7, 90, dimensionStyle);
                    fun.dxflinedim(dxf, dim_s, s);
                    //Angular2LineDimension dim_alphan = new Angular2LineDimension(new Line(m4, m7), new Line(m4, m3), 1, dimensionStyle);
                    //dim_alphan.UserText = alphan * 180 / pi + "°" + "+90°";
                    //dim_alphan.SetDimensionLinePosition(new Vector2(m7.X + 2, m7.Y + 2));
                    //dxf.AddEntity(dim_alphan);
                    //左视图
                    Vector2 z3 = new Vector2(m1.X + offset * 3, m1.Y);
                    Vector2 z4 = new Vector2(z3.X, z3.Y + h2);
                    Vector2 z1 = new Vector2(z3.X + c4.Y - ii4.Y, z3.Y + h1 - s);
                    Vector2 z2 = new Vector2(z1.X, z3.Y);
                    Vector2 z5 = new Vector2(z3.X + c2.Y - i2.Y, z3.Y + h1);
                    Vector2 z6 = new Vector2(z3.X + c2.Y - (iarc1.Center.Y - iarc1.Radius), z5.Y);
                    Vector2 z7 = new Vector2(z3.X + c2.Y - ii2.Y, z1.Y);
                    Vector2 z8 = new Vector2(z3.X + c2.Y - ii3.Y, z1.Y);
                    Vector2 z9 = new Vector2(z8.X, z3.Y);
                    Vector2 z10 = new Vector2(z3.X + c2.Y - i3.Y, z5.Y);
                    LwPolyline zPline = AddPointsToLwPolyLine(z1, z2, z3, z4, z5, z7);
                    fun.PolyFill(dxf, zPline, 0.1, contour);
                    LwPolyline zCutting = AddPointsToLwPolyLine(z5, z6, z1, z7);
                    zCutting.IsClosed = true;
                    fun.PolyFill(dxf, zCutting, 0.1, cutting);
                    DrawPlineByTwoPoints(dxf, z8, z10, cutting);
                    DrawPlineByTwoPoints(dxf, z9, z8);
                    //左视图标注
                    LinearDimension dim_zs = new LinearDimension(new Line(z8, z6), offset, -90, dimensionStyle);
                    fun.dxflinedim(dxf, dim_zs, s);
                    //Angular2LineDimension dim_alphan_z = new Angular2LineDimension(new Line(z5, z4), new Line(z5, z7), 1, dimensionStyle);
                    //dim_alphan_z.UserText = alphan * 180 / pi + "°" + "+90°";
                    //dim_alphan_z.SetDimensionLinePosition(new Vector2(z5.X - 2, z5.Y - 2));
                    //dxf.AddEntity(dim_alphan_z);
                    dxf.DrawingVariables.AcadVer = DxfVersion.AutoCad2007;
                    dxf.Save(path);
                }
        */
        /*        public static void StyleS_InsertS(Dictionary<string, Object> data)
                {
                    DxfDocument dxf = new DxfDocument();
                    Layer contour = new Layer("contour") { Color = AciColor.Cyan };    //1,轮廓层
                    Layer cutting = new Layer("cutting") { Color = AciColor.Red };    //切削层

                    string path = Convert.ToString(data["path"]);
                    //参数名称取自ISO 5610-2
                    double b = 12;
                    double l1 = 90;
                    double l2 = 32;
                    double f = 16;
                    double l3 = 9.525;
                    double h2 = 12;
                    double h1 = 12;
                    double s = 3.97;
                    double insertAngle = 90 * pi / 180;
                    double alphan = 7 * pi / 180;
                    double cutagl = 45 * pi / 180;
                    double lambdas = 0;
                    double gammao = 0;
                    double repsilon = 0;
                    #region
                    try
                    {
                        if (data["re"] != null)
                            repsilon = Convert.ToDouble(data["re"]);
                        if (repsilon <= 0)
                            repsilon = 0.01;
                    }
                    catch (KeyNotFoundException) { }
                    try
                    {
                        if (data["lams"] != null)
                            lambdas = Convert.ToDouble(data["lams"]) * pi / 180;
                    }
                    catch (KeyNotFoundException) { }
                    try
                    {
                        if (data["gamo"] != null)
                            gammao = Convert.ToDouble(data["gamo"]) * pi / 180;
                    }
                    catch (KeyNotFoundException) { }
                    try
                    {
                        if (data["b"] != null)
                            b = Convert.ToDouble(data["b"]);
                    }
                    catch (KeyNotFoundException) { }
                    try
                    {
                        if (data["s"] != null)
                            s = Convert.ToDouble(data["s"]);
                    }
                    catch (KeyNotFoundException) { }
                    try
                    {
                        if (data["lf"] != null)
                            l1 = Convert.ToDouble(data["lf"]);
                    }
                    catch (KeyNotFoundException) { }
                    try
                    {
                        if (data["lh"] != null)
                            l2 = Convert.ToDouble(data["lh"]);
                    }
                    catch (KeyNotFoundException) { }
                    try
                    {
                        if (data["wf"] != null)
                            f = Convert.ToDouble(data["wf"]);
                    }
                    catch (KeyNotFoundException) { }
                    try
                    {
                        if (data["h"] != null)
                            h2 = Convert.ToDouble(data["h"]);
                    }
                    catch (KeyNotFoundException) { }
                    try
                    {
                        if (data["hf"] != null)
                            h1 = Convert.ToDouble(data["hf"]);
                    }
                    catch (KeyNotFoundException) { }
                    try
                    {
                        if (data["epsr"] != null)
                            insertAngle = Convert.ToDouble(data["epsr"]) * pi / 180;
                    }
                    catch (KeyNotFoundException) { }
                    try
                    {
                        if (data["kapr"] != null)
                            cutagl = Convert.ToDouble(data["kapr"]) * pi / 180;
                    }
                    catch (KeyNotFoundException) { }
                    try
                    {
                        if (data["an"] != null)
                            alphan = Convert.ToDouble(data["an"]) * pi / 180;
                    }
                    catch (KeyNotFoundException) { }
                    try
                    {
                        if (data["ic"] != null)
                            l3 = Pus.GetLByIC(Convert.ToDouble(data["ic"]), insertAngle);
                    }
                    catch (KeyNotFoundException) { }
                    #endregion
                    double kscale = 1;
                    if (l1 >= 120)
                        kscale = 1;
                    else
                        kscale = 1.5;
                    double lineWidth = 1;
                    //k点位置恒定
                    Vector3 k = new Vector3(0, 0, 0);
                    RectShank rs = new RectShank(b, l1, f, l2, l3, 4, false, insertAngle, cutagl, lambdas, false, gammao, alphan, s, repsilon);
                    Vector3[] shank = rs.Shank;
                    Vector3[] inserts = rs.Inserts;
                    //线性变换
                    double theta = 0 * pi / 180;
                    Matrix3 linearTrans = new Matrix3(
                        Math.Cos(theta) * kscale, -Math.Sin(theta) * kscale, 0,
                        Math.Sin(theta) * kscale, Math.Cos(theta) * kscale, 0,
                                      0, 0, kscale
                    );
                    for (int i = 0; i < shank.Length; i++)
                    {
                        shank[i] = linearTrans * shank[i];
                    }
                    for (int i = 0; i < inserts.Length; i++)
                    {
                        inserts[i] = linearTrans * inserts[i];
                    }

                    //刀头部分
                    Vector3[] head = new Vector3[11];
                    Face3d fb = new Face3d(shank[1], shank[2], shank[3]);
                    Face3d fbk = new Face3d(shank[1], shank[5], shank[6]);
                    Face3d ff = new Face3d(shank[0], shank[3], shank[4]);
                    Face3d fiu = new Face3d(inserts[4], inserts[5], inserts[6]);
                    Vector3 nbu = Pus.UnitVector(shank[0], shank[4]);
                    int icp = inserts.Length / 2;
                    head[0] = Pus.Inters(fb, inserts[3], inserts[3] + nbu);
                    head[1] = Pus.Inters(fb, inserts[0], inserts[0] + nbu);
                    Face3d fd0 = new Face3d(inserts[0], inserts[3], head[0]);
                    Face3d ft = new Face3d(inserts[0], head[1], new Vector3(shank[7].X, shank[7].Y - kscale * 1.5, shank[7].Z));
                    head[5] = Pus.Inters(ft, inserts[4], inserts[5]);
                    Face3d fcon = new Face3d(shank[2], shank[6], shank[7]);
                    head[2] = Pus.Inters(fcon, Pus.Inters(ft, fb, head[1]));
                    head[3] = shank[3];
                    head[6] = Pus.Inters(fcon, Pus.Inters(ft, fiu, head[5]));
                    head[7] = shank[7];
                    Face3d fd1 = new Face3d(inserts[3], head[0], inserts[2]);
                    head[10] = Pus.Inters(fd1, inserts[5], inserts[6]);
                    head[4] = Pus.Inters(fbk, Pus.Inters(fb, fd1, head[0]));
                    head[9] = Pus.Inters(fbk, Pus.Inters(fiu, fd1, head[10]));
                    head[8] = Pus.Inters(fiu, shank[2], shank[6]);



                    //mview
                    LwPolyline msk = Pus.AddPointsToLwPolyLine(shank[4], shank[5], shank[6], shank[7]);
                    msk.IsClosed = true;
                    fun.PolyFill(dxf, msk, lineWidth, contour);

                    LwPolyline mhd = Pus.AddPointsToLwPolyLine(head[5], head[6], head[7], head[8], head[9], head[10], inserts[5]);
                    mhd.IsClosed = true;
                    fun.PolyFill(dxf, mhd, lineWidth, contour);

                    LwPolyline mist = Pus.AddPointsToLwPolyLine(inserts[4], inserts[5], inserts[6], inserts[7]);
                    mist.IsClosed = true;
                    Pus.AglToArc(mist, repsilon);
                    fun.PolyFill(dxf, mist, lineWidth, cutting);


                    //mview标注
                    DimensionStyle dimensionStyle = new DimensionStyle("mystyle");
                    dimensionStyle.ArrowSize = kscale * 1.5;
                    dimensionStyle.DimArrow1 = DimensionArrowhead.Closedfilled;
                    dimensionStyle.DimArrow2 = DimensionArrowhead.Closedfilled;
                    dimensionStyle.TextHeight = kscale * 1.5;
                    dimensionStyle.TextOffset = kscale;
                    double offset = 7 * kscale;
                    LinearDimension dim_b = new LinearDimension(new Line(shank[5], shank[4]), offset, Pus.Degree(shank[5], shank[4]), dimensionStyle);
                    fun.dxflinedim(dxf, dim_b, b);
                    LinearDimension dim_f = new LinearDimension(new Line(Vector3.Zero, head[8]), Vector2.Distance(Vector2.Zero, Pus.ToV2(head[8])) / 2 + offset, Pus.Degree(shank[4], shank[5]), dimensionStyle);
                    fun.dxflinedim(dxf, dim_f, f);
                    LinearDimension dim_l1 = new LinearDimension(new Line(Vector3.Zero, shank[4]), b / 2 * kscale, 180, dimensionStyle);
                    fun.dxflinedim(dxf, dim_l1, l1);
                    LinearDimension dim_l2 = new LinearDimension(new Line(shank[6], Pus.ReferenceV3(Pus.GetArcFromPline(mist, 4).Center, -repsilon, 0, 0)), Vector2.Distance(Pus.ToV2(inserts[7]), Pus.ToV2(head[8])) / 3, 0, dimensionStyle);
                    fun.dxflinedim(dxf, dim_l2, l2);
                    Angular2LineDimension dim_cutagl = new Angular2LineDimension(new Line(inserts[4], inserts[7]),
                        new Line(Pus.ToV2(inserts[4]), fun.Polar(Pus.ToV2(inserts[4]), pi, 1)), offset, dimensionStyle);
                    dim_cutagl.UserText = Math.Round(cutagl * 180 / pi, 1) + "°";
                    dxf.AddEntity(dim_cutagl);

                    //zview
                    //绕y轴旋转pi/2再平移得到左视图
                    Vector3[] zshank = new Vector3[shank.Length];
                    Vector3[] zhead = new Vector3[head.Length];
                    Vector3[] zinserts = new Vector3[inserts.Length];
                    Vector3 zviewMkr = new Vector3(0, 1, 0);
                    double yR = pi / 2;
                    double zoffset = -2 * b * kscale;
                    for (int i = 0; i < shank.Length; i++)
                    {
                        zshank[i] = Pus.Rodrigue(zviewMkr, 1, yR, shank[i]);
                        zshank[i].X += zoffset;
                    }
                    for (int i = 0; i < inserts.Length; i++)
                    {
                        zinserts[i] = Pus.Rodrigue(zviewMkr, 1, yR, inserts[i]);
                        zinserts[i].X += zoffset;
                    }
                    for (int i = 0; i < head.Length; i++)
                    {
                        zhead[i] = Pus.Rodrigue(zviewMkr, 1, yR, head[i]);
                        zhead[i].X += zoffset;
                    }
                    Vector3 zk = k;
                    zk.X += zoffset;
                    LwPolyline zfd0 = Pus.AddPointsToLwPolyLine(zhead[0], zhead[1], zinserts[0], zinserts[3]);
                    zfd0.IsClosed = true;
                    fun.PolyFill(dxf, zfd0, lineWidth, contour);
                    LwPolyline zfd1 = Pus.AddPointsToLwPolyLine(zinserts[3], zhead[0], zhead[4], zhead[9], zhead[10]);
                    fun.PolyFill(dxf, zfd1, lineWidth, contour);


                    LwPolyline zist0 = Pus.AddPointsToLwPolyLine(zinserts[0], zinserts[4], zinserts[7], zinserts[3]);
                    zist0.IsClosed = true;
                    fun.PolyFill(dxf, zist0, lineWidth, cutting);
                    LwPolyline zist1 = Pus.AddPointsToLwPolyLine(zinserts[3], zinserts[7], zinserts[6], zinserts[2]);
                    zist1.IsClosed = true;
                    fun.PolyFill(dxf, zist1, lineWidth, cutting);

                    if (zinserts[7].X < zinserts[5].X)
                    {
                        LwPolyline zfiu = Pus.AddPointsToLwPolyLine(zinserts[5], zhead[5], zhead[6], zhead[8], zhead[9], zhead[10]);
                        zfiu.IsClosed = true;
                        fun.PolyFill(dxf, zfiu, lineWidth, contour);

                        LwPolyline zistu = Pus.AddPointsToLwPolyLine(zinserts[4], zinserts[5], zinserts[6], zinserts[7]);
                        zistu.IsClosed = true;
                        fun.PolyFill(dxf, zistu, lineWidth, cutting);
                    }
                    //zview标注
                    LinearDimension dim_h1 = new LinearDimension(new Line(zk, zhead[1]), offset * 0.7, Pus.Degree(zshank[4], zshank[0]), dimensionStyle);
                    fun.dxflinedim(dxf, dim_h1, h1);

                    Vector2 z4 = Pus.ToV2(zinserts[4]);
                    if (lambdas == 0)
                    {
                        lambdas = 0.1 * pi / 180;
                        Pus.NeedleDim(dxf, new Line(z4, fun.Polar(z4, -pi / 2, 1)),
                            new Line(z4, fun.Polar(z4, -pi / 2 + lambdas, 1)), offset * 1.7, "λs=0°", dimensionStyle);
                    }
                    else
                    {
                        Pus.NeedleDim(dxf, new Line(z4, fun.Polar(z4, -pi / 2, 1)),
                            new Line(z4, fun.Polar(z4, -pi / 2 + lambdas, 1)), offset * 1.7, "λs=" + Math.Round(lambdas * 180 / pi, 2) + "°", dimensionStyle);
                    }

                    //lview
                    Vector3[] lshank = new Vector3[shank.Length];
                    Vector3[] linserts = new Vector3[inserts.Length];
                    Vector3[] lhead = new Vector3[head.Length];
                    //放倒
                    Vector3 laydown = new Vector3(-1, 0, 0);
                    double laydownR = pi / 2;
                    double loffset = -h2 * 2 * kscale;
                    for (int i = 0; i < shank.Length; i++)
                    {
                        lshank[i] = Pus.Rodrigue(laydown, 1, laydownR, shank[i]);
                        lshank[i].Y += loffset;
                    }

                    for (int i = 0; i < inserts.Length; i++)
                    {
                        linserts[i] = Pus.Rodrigue(laydown, 1, laydownR, inserts[i]);
                        linserts[i].Y += loffset;
                    }

                    for (int i = 0; i < head.Length; i++)
                    {
                        lhead[i] = Pus.Rodrigue(laydown, 1, laydownR, head[i]);
                        lhead[i].Y += loffset;
                    }
                    Vector3 lk = k;
                    lk.Y += loffset;

                    LwPolyline lsk = Pus.AddPointsToLwPolyLine(lshank[0], lshank[4], lshank[7], lshank[3]);
                    lsk.IsClosed = true;
                    fun.PolyFill(dxf, lsk, lineWidth, contour);

                    LwPolyline lft = Pus.AddPointsToLwPolyLine(lhead[1], lhead[2], lhead[6], lhead[5]);
                    fun.PolyFill(dxf, lft, lineWidth, contour);
                    LwPolyline lfd0 = Pus.AddPointsToLwPolyLine(lhead[0], lhead[1], linserts[0], linserts[3]);
                    lfd0.IsClosed = true;
                    fun.PolyFill(dxf, lfd0, lineWidth, contour);

                    LwPolyline list0 = Pus.AddPointsToLwPolyLine(linserts[0], linserts[4], linserts[7], linserts[3]);
                    list0.IsClosed = true;
                    fun.PolyFill(dxf, list0, lineWidth, cutting);

                    if (linserts[6].Y > linserts[4].Y)
                    {
                        LwPolyline lfiu = Pus.AddPointsToLwPolyLine(lhead[5], lhead[6], lhead[8], lhead[9], lhead[10], linserts[5]);
                        lfiu.IsClosed = true;
                        fun.PolyFill(dxf, lfiu, lineWidth, contour);

                        LwPolyline listu = Pus.AddPointsToLwPolyLine(linserts[4], linserts[5], linserts[6], linserts[7]);
                        listu.IsClosed = true;
                        fun.PolyFill(dxf, listu, lineWidth, cutting);

                    }
                    //lview标注
                    Vector2 list7 = Pus.ToV2(linserts[7]);
                    if (gammao == 0)
                    {
                        gammao = 0.1 * pi / 180;
                        Pus.NeedleDim(dxf, new Line(linserts[6], linserts[7]),
                            new Line(list7, fun.Polar(list7, Pus.AngleOnP(linserts[6], linserts[7]) + gammao, 1)), offset * 1.3, "γn=0°", dimensionStyle);
                    }
                    else
                    {
                        Pus.NeedleDim(dxf, new Line(linserts[6], linserts[7]),
                            new Line(list7, fun.Polar(list7, Pus.AngleOnP(linserts[6], linserts[7]) + gammao, 1)), offset, "γn=" + Math.Round(gammao * 180 / pi, 2) + "°", dimensionStyle);
                    }
                    LinearDimension dim_h2 = new LinearDimension(new Line(lshank[4], lshank[0]), offset, Pus.Degree(lshank[4], lshank[0]), dimensionStyle);
                    fun.dxflinedim(dxf, dim_h2, h2);


                    //图框
                    Vector2 a3xsize = Frame.A3X;
                    double isframe = 0;
                    try
                    {
                        isframe = Convert.ToDouble(data["isframe"]);
                    }
                    catch (KeyNotFoundException) { }
                    if (isframe != 0)
                    {
                        Vector2 EntitysCenter = new Vector2((shank[4].X + zhead[0].X) / 2, (shank[4].Y + lshank[0].Y) / 2);
                        Vector2 p0 = new Vector2(EntitysCenter.X - a3xsize.X / 2, EntitysCenter.Y + a3xsize.Y / 2);
                        Dictionary<string, Vector2> positions = Frame.frameA3X(dxf, p0);
                        Vector2 kp = p0;
                        try
                        {
                            kp = positions["比例"];
                            fun.writetextofC(dxf, kscale + ":1", positions["比例"], 3.5, 0, 0.6, 3);
                        }
                        catch (Exception) { }
                    }

                    dxf.DrawingVariables.AcadVer = DxfVersion.AutoCad2007;
                    dxf.Save(path);
                }
        */
        /*        public static void StyleS_InsertR(Dictionary<string, Object> data)
                {
                    DxfDocument dxf = new DxfDocument();
                    Layer contour = new Layer("contour") { Color = AciColor.Cyan };    //1,轮廓层
                    Layer cutting = new Layer("cutting") { Color = AciColor.Red };    //切削层

                    string path = Convert.ToString(data["path"]);
                    double pi = Math.PI;
                    //参数名称取自ISO 5610-2
                    double b = 8;
                    double d = 6;
                    double l1 = 70;
                    double l2 = 25;
                    double f = 10;
                    double l3 = 9.525;
                    double h2 = 8;
                    double h1 = 8;
                    double s = 2.38;
                    double alphan = 7 * pi / 180;
                    double lambdas = 0;
                    double gamao = 0;
                    double repsilon = 0;
                    #region 13399中的参数名称与之对应
                    try
                    {
                        if (data["re"] != null)
                            repsilon = Convert.ToDouble(data["re"]);
                    }
                    catch (KeyNotFoundException) { }
                    try
                    {
                        if (data["lams"] != null)
                            lambdas = Convert.ToDouble(data["lams"]) * pi / 180;
                    }
                    catch (KeyNotFoundException) { }
                    try
                    {
                        if (data["gamo"] != null)
                            gamao = Convert.ToDouble(data["gamo"]) * pi / 180;
                    }
                    catch (KeyNotFoundException) { }
                    try
                    {
                        if (data["b"] != null)
                            b = Convert.ToDouble(data["b"]);
                    }
                    catch (KeyNotFoundException) { }
                    try
                    {
                        if (data["ic"] != null)
                            d = Convert.ToDouble(data["ic "]);
                    }
                    catch (KeyNotFoundException) { }
                    try
                    {
                        if (data["s"] != null)
                            s = Convert.ToDouble(data["s"]);
                    }
                    catch (KeyNotFoundException) { }
                    try
                    {
                        if (data["l"] != null)
                            l3 = Convert.ToDouble(data["l"]);
                    }
                    catch (KeyNotFoundException) { }
                    try
                    {
                        if (data["lf"] != null)
                            l1 = Convert.ToDouble(data["lf"]);
                    }
                    catch (KeyNotFoundException) { }
                    try
                    {
                        if (data["lh"] != null)
                            l2 = Convert.ToDouble(data["lh"]);
                    }
                    catch (KeyNotFoundException) { }
                    try
                    {
                        if (data["wf"] != null)
                            f = Convert.ToDouble(data["wf"]);
                    }
                    catch (KeyNotFoundException) { }
                    try
                    {
                        if (data["h"] != null)
                            h2 = Convert.ToDouble(data["h"]);
                    }
                    catch (KeyNotFoundException) { }
                    try
                    {
                        if (data["hf"] != null)
                            h1 = Convert.ToDouble(data["hf"]);
                    }
                    catch (KeyNotFoundException) { }
                    try
                    {
                        if (data["an"] != null)
                            alphan = Convert.ToDouble(data["an"]) * pi / 180;
                    }
                    catch (KeyNotFoundException) { }
                    Dictionary<double, double> l3_repsilon = new Dictionary<double, double> {
                                { 6.4,0.4},
                                { 9.525,0.8},
                                { 12.7,0.8},
                                { 15.875,1.2},
                                { 19.05,1.2},
                                { 25.4,2.4},
                            };
                    #endregion
                    //俯视图
                    Vector2 c0 = new Vector2(0, 0);
                    Vector2 c1 = c0;
                    Vector2 c2 = new Vector2(c1.X, c1.Y + b);
                    Vector2 c3 = new Vector2(c2.X - l1 + l2, c2.Y);
                    Vector2 c5 = new Vector2(c3.X, c1.Y);
                    Vector2 insertCen = new Vector2(c1.X - l1 + d / 2, c3.Y - f + d / 2);
                    Circle insert = new Circle(insertCen, d / 2);
                    fun.drawcircle(dxf, insertCen, d / 2, 0.1, cutting);
                    //偏移后的刀片底部外轮廓
                    double insert_offset = s * Math.Tan(alphan);
                    Circle buttom_insert = new Circle(insertCen, d / 2 - insert_offset);
                    //切点q1,q2
                    Vector2 q1 = fun.Polar(insertCen, 1.5 * pi, buttom_insert.Radius);
                    Vector2 q2 = fun.Polar(insertCen, 0.75 * pi, buttom_insert.Radius);
                    Vector2 c4 = fun.Inters(q1, new Vector2(q1.X + 1, q1.Y + 1), c2, c3);
                    Vector2 x2 = LineXCir(insert, c4, q2)[1];
                    Vector2 c6 = new Vector2(c5.X - 2, q1.Y);
                    Vector2 x1 = LineXCir(insert, q1, c6)[1];
                    LwPolyline pline = AddPointsToLwPolyLine(x1, c6, c5, c1, c2, c3, c4, x2);
                    fun.PolyFill(dxf, pline, 0.1, contour);
                    DrawPlineByTwoPoints(dxf, c3, c5, contour);
                    DimensionStyle dimensionStyle = fun.CreateDimStyle();
                    dimensionStyle.ArrowSize = 0.2;
                    dimensionStyle.DimArrow1 = DimensionArrowhead.Closedfilled;
                    dimensionStyle.DimArrow2 = DimensionArrowhead.Closedfilled;
                    dimensionStyle.TextHeight = 0.5;
                    double offset = 7;
                    Vector2 cir1 = new Vector2(c1.X - l1, insertCen.Y);
                    Vector2 cir2 = new Vector2(insertCen.X, insertCen.Y - d / 2);
                    Vector2 cir3 = new Vector2(insertCen.X, insertCen.Y + d / 2);
                    LinearDimension dim_l1 = new LinearDimension(new Line(cir1, c1), 1.5 * offset, -180, dimensionStyle);
                    fun.dxflinedim(dxf, dim_l1, l1);
                    LinearDimension dim_l2 = new LinearDimension(new Line(cir1, c5), offset, -180, dimensionStyle);
                    fun.dxflinedim(dxf, dim_l2, l2);
                    LinearDimension dim_b = new LinearDimension(new Line(c2, c1), offset, -90, dimensionStyle);
                    fun.dxflinedim(dxf, dim_b, b);
                    LinearDimension dim_f = new LinearDimension(new Line(cir2, c4), offset * 2, 90, dimensionStyle);
                    fun.dxflinedim(dxf, dim_f, f);
                    LinearDimension dim_d = new LinearDimension(new Line(cir3, cir2), offset * 0.7, 90, dimensionStyle);
                    fun.dxflinedim(dxf, dim_d, d);
                    //主视图
                    Vector2 m1 = new Vector2(c1.X, c2.Y + offset);
                    Vector2 m2 = new Vector2(m1.X, m1.Y + h2);
                    Vector2 m3 = new Vector2(c5.X, m2.Y);
                    //刀片上第二个弧的结束点的x坐标小于x1的坐标
                    Vector2 m4 = new Vector2(x1.X, m1.Y + h1);
                    Vector2 m5 = new Vector2(cir1.X, m4.Y);
                    Vector2 m6 = new Vector2(cir1.X + insert_offset, m5.Y - s);
                    Vector2 m7 = new Vector2(q1.X, m4.Y - s);
                    Vector2 m8 = new Vector2(m6.X, m1.Y);
                    Vector2 m9 = new Vector2(c6.X, m1.Y + h2);
                    Vector2 m10 = new Vector2(c6.X, m1.Y);
                    Vector2 m11 = new Vector2(m3.X, m1.Y);
                    LwPolyline polylineM = AddPointsToLwPolyLine(m6, m8, m1, m2, m4, m7);
                    fun.PolyFill(dxf, polylineM, 0.1, contour);
                    LwPolyline insertM = AddPointsToLwPolyLine(m4, m5, m6, m7);
                    fun.PolyFill(dxf, insertM, 0.1, cutting);
                    DrawPlineByTwoPoints(dxf, m3, m11);
                    DrawPlineByTwoPoints(dxf, m9, m10);
                    //主视图标注
                    LinearDimension dim_h2 = new LinearDimension(new Line(m1, m2), offset, -90, dimensionStyle);
                    fun.dxflinedim(dxf, dim_h2, h2);
                    LinearDimension dim_h1 = new LinearDimension(new Line(m5, m8), offset * 1.5, 90, dimensionStyle);
                    fun.dxflinedim(dxf, dim_h1, h1);
                    LinearDimension dim_s = new LinearDimension(new Line(m5, m6), offset * 0.7, 90, dimensionStyle);
                    fun.dxflinedim(dxf, dim_s, s);
                    Angular2LineDimension dim_alphan = new Angular2LineDimension(new Line(m5, new Vector2(m5.X - 1, m5.Y)), new Line(m5, m6), 1, dimensionStyle);
                    dim_alphan.UserText = alphan * 180 / pi + "°" + "+90°";
                    dim_alphan.SetDimensionLinePosition(new Vector2(m5.X - 3, m5.Y - 3));
                    dxf.AddEntity(dim_alphan);
                    ////左视图
                    Vector2 z3 = new Vector2(m1.X + offset * 3, m1.Y);
                    Vector2 z4 = new Vector2(z3.X, z3.Y + h2);
                    Vector2 z1 = new Vector2(z3.X + c4.Y - q1.Y, z3.Y + h1 - s);
                    Vector2 z2 = new Vector2(z1.X, z3.Y);
                    Vector2 z5 = new Vector2(z3.X + c2.Y - x2.Y, z3.Y + h1);
                    Vector2 z6 = new Vector2(z3.X + c2.Y - cir2.Y, z5.Y);
                    Vector2 z7 = new Vector2(z3.X + c2.Y - q2.Y, z1.Y);
                    LwPolyline zPline = AddPointsToLwPolyLine(z1, z2, z3, z4, z5, z7);
                    fun.PolyFill(dxf, zPline, 0.1, contour);
                    LwPolyline zCutting = AddPointsToLwPolyLine(z5, z6, z1, z7);
                    fun.PolyFill(dxf, zCutting, 0.1, cutting);
                    //左视图标注
                    LinearDimension dim_zs = new LinearDimension(new Line(z1, z6), offset * 0.6, -90, dimensionStyle);
                    fun.dxflinedim(dxf, dim_zs, s);
                    Angular2LineDimension dim_alphan_z = new Angular2LineDimension(new Line(z1, z6), new Line(z6, new Vector2(z6.X + 1, z6.Y)), 1, dimensionStyle);
                    dim_alphan_z.UserText = alphan * 180 / pi + "°" + "+90°";
                    dim_alphan_z.SetDimensionLinePosition(new Vector2(z6.X + 4, z6.Y - 4));
                    dxf.AddEntity(dim_alphan_z);
                    dxf.DrawingVariables.AcadVer = DxfVersion.AutoCad2007;
                    dxf.Save(path);
                }
        */
        public static void StyleS_InsertC(Dictionary<string, Object> data)
        {
            DxfDocument dxf = new DxfDocument();

            #region 图层

            Layer contour = fun.SetLayer("contour");//轮廓层
            Layer dimensioning = fun.SetLayer("dimensioning");//尺寸层
            Layer refin = fun.SetLayer("refin");//基准线/内轮廓/虚线
            Layer center = fun.SetLayer("center");//中心线
            Layer textlayer = fun.SetLayer("textlayer");//文本层
            Layer hatching = fun.SetLayer("hatching");//填充层
            Layer additionalline = fun.SetLayer("additionalline");//附加线
            Layer cutting = fun.SetLayer("cutting");//切削层

            #endregion

            #region 变量

            string path = Convert.ToString(data["path"]);

            double h1 = 34.65;
            double b = 34.71;
            double l3 = 22;
            double a = 13.69;
            double f = 40.56;
            double h2 = 33.94;
            double l1 = 148.63;
            double l2 = 40.85;
            double s = 8;
            double r = 1;

            double scale = 1;
            //double scale = Convert.ToDouble(data["scale"]);
            //double h1 = Convert.ToDouble(data["hf"]) * scale;
            //double b = Convert.ToDouble(data["b"]) * scale;
            //double l3 = Convert.ToDouble(data["l3"]) * scale;
            //double a = Convert.ToDouble(data["a"]) * scale;
            //double f = Convert.ToDouble(data["wf"]) * scale;
            //double h2 = Convert.ToDouble(data["h"]) * scale;
            //double l1 = Convert.ToDouble(data["lf"]) * scale;
            //double l2 = Convert.ToDouble(data["lh"]) * scale;
            //double s = Convert.ToDouble(data["s"]) * scale;
            //double r = Convert.ToDouble(data["re"]) * scale;

            double h1s = h1 / 34.65;
            double h2s = h2 / 33.94;
            double l2s = l2 / 40.85;
            double fs = f / 40.56;
            double ss = s / 8;


            double pi = Math.PI;
            double rad = pi / 180;
            double offset = 10;
            double textHeight = 3.5;


            #endregion

            #region 点

            //右
            Vector2 v0 = new Vector2(0, 0);
            Vector2 v1 = new Vector2(0, l1 / 2);
            Vector2 v2 = fun.Polar2(v1, 16.93 * h2s, -90);
            Vector2 v3 = fun.Polar2(v2, h2, -90);
            Vector2 v4 = fun.Polar2(v1, l1 / 2, -90);
            Vector2 v5 = fun.Polar2(v1, l1 + a - l2, -90);
            Vector2 v6 = fun.Polar2(v5, 16 * l2s, -90);
            Vector2 v17 = new Vector2(v1.X + f, v1.Y - l1);
            Vector2 v18 = fun.Polar2(v17, l3, 135);
            Vector2 v15 = fun.Polar2(v18, l3, -135);
            Vector2 v16 = fun.Polar2(v17, l3, -135);
            Vector2 v7 = fun.Polar2(v15, r, 45);
            Vector2 v8 = fun.Polar2(v17, r, 135);
            Vector2 v9 = fun.Polar2(v8, 20.58 * l2s, 90);
            Vector2 v10 = fun.Polar2(v5, b, 0);
            Vector2 v11 = fun.Polar2(v4, b, 0);
            Vector2 v12 = fun.Polar2(v3, b, 0);
            Vector2 v13 = fun.Polar2(v2, b, 0);
            Vector2 v14 = fun.Polar2(v1, b, 0);

            Vector2 vc1 = fun.Polar2((v15 + v17) / 2, l3 * 1.5, -135);
            Vector2 vc2 = fun.Polar2((v15 + v17) / 2, l3 * 1.5, -135);
            Vector2 vc3 = fun.Polar2((v15 + v17) / 2, l3 * 1.5, -135);
            Vector2 vc4 = fun.Polar2((v15 + v17) / 2, l3 * 1.5, -135);


            //左1
            Vector2 v19 = Vector2.Polar(v18, s, 164 * rad);
            Vector2 v20 = Vector2.Polar(v19, 17.72 * l2s, 74 * rad);
            Vector2 v21 = Vector2.Polar(v18, 17.72, 74 * rad);
            Vector2 v22 = Vector2.Polar(v19, 30.3, 74 * rad);

            Vector2 v23 = Vector2.Polar(v19, s * 2, 180 * rad);
            Vector2 v24 = Vector2.Polar(v23, 10.52, 180 * rad);
            Vector2 v25 = Vector2.Polar(v24, 7.3, 180 * rad);
            Vector2 v26 = Vector2.Polar(v25, 17.99, 75 * rad);
            Vector2 v27 = Vector2.Polar(v24, 14.5, 75 * rad);
            Vector2 v28 = Vector2.Polar(v25, 30.67, 75 * rad);

            //左2
            Vector2 v29 = Vector2.Polar(v1, 100.69, (180 + 62) * rad);
            Vector2 v30 = Vector2.Polar(v29, 6, (180 + 68) * rad);
            Vector2 v31 = Vector2.Polar(v30, 17, (180 - 15) * rad);
            Vector2 v32 = Vector2.Polar(v29, 20.0, (180 - 15) * rad);
            Vector2 v33 = Vector2.Polar(v29, h1, (180 + 68) * rad);
            Vector2 v34 = Vector2.Polar(v33, 27.16, (180 - 15) * rad);
            Vector2 v35 = Vector2.Polar(v29, 30, (180 - 15) * rad);

            //左3
            Vector2 v36 = Vector2.Polar(v1, 157.0, -108 * rad);
            Vector2 v37 = Vector2.Polar(v36, 6.9, -113 * rad);
            Vector2 v38 = Vector2.Polar(v37, 18.1, (180 - 21) * rad);
            Vector2 v39 = Vector2.Polar(v36, 18.1, (180 - 21) * rad);
            Vector2 v40 = Vector2.Polar(v36, h1, -113 * rad);
            Vector2 v41 = Vector2.Polar(v40, 28.09, (180 - 15) * rad);
            Vector2 v42 = Vector2.Polar(v36, 31.45, (180 - 21) * rad);

            //左4
            Vector2 v43 = Vector2.Polar(v1, 213, -103 * rad);
            Vector2 v44 = Vector2.Polar(v43, 6, -113 * rad);
            Vector2 v45 = Vector2.Polar(v44, 18, (180 - 9) * rad);
            Vector2 v46 = Vector2.Polar(v43, 21, (180 - 9) * rad);
            Vector2 v47 = Vector2.Polar(v43, h1, -113 * rad);
            Vector2 v48 = Vector2.Polar(v47, 28.45, (180 - 15) * rad);
            Vector2 v49 = Vector2.Polar(v43, 30.86, (180 - 9) * rad);

            #endregion

            #region 线

            //右
            Line lc01 = new Line(vc1, vc2);
            Line lc02 = new Line(vc3, vc4);
            Line line01 = new Line(v6, v13);
            LwPolyline lw01 = Pus.AddPointsToLwPolyLine(Vector2.Polar(Vector2.Polar(v9, l3, 165 * rad), r, 75 * rad), v12, v13, v14, v15, v16, v1, v2, v3, v4, v5, v6, v7, Vector2.Polar(v8, r, 165 * rad));
            LwPolyline lw02 = Pus.AddPointsToLwPolyLine(v3, v4, v15, v16, v3);
            LwPolyline lw03 = Pus.AddPointsToLwPolyLine(fun.Polar2(v9, 13 / 2, 75), v9, v10, v11, v8, fun.Polar2(v9, 13 / 2, 75));

            lw03 = Pus.Fillet4LwPline(lw03, 1, r);
            lw03 = Pus.Fillet4LwPline(lw03, 3, r);
            lw03 = Pus.Fillet4LwPline(lw03, 5, r);
            lw03 = Pus.Fillet4LwPline(lw03, 7, r);

            fun.AddHatch(dxf, hatching, lw02, new Line[32], new Arc[32], 45, 10);

            //左1
            LwPolyline lw11 = Pus.AddPointsToLwPolyLine(v18, v19, v20, v21, v18);
            LwPolyline lw12 = Pus.AddPointsToLwPolyLine(v17, v22, v20, v21, v18, v17);
            lw12.Vertexes[0].Bulge = Math.Tan(60 * rad / 4);

            LwPolyline lw13 = Pus.AddPointsToLwPolyLine(v24, v25, v26, v27, v24);
            LwPolyline lw14 = Pus.AddPointsToLwPolyLine(v23, v28, v26, v27, v24, v23);
            lw14.Vertexes[0].Bulge = Math.Tan(60 * rad / 4);

            fun.AddHatch(dxf, hatching, lw11, new Line[32], new Arc[32], 45, 10);
            fun.AddHatch(dxf, hatching, lw12, new Line[32], new Arc[32], -45, 10);
            fun.AddHatch(dxf, hatching, lw13, new Line[32], new Arc[32], 45, 10);
            fun.AddHatch(dxf, hatching, lw14, new Line[32], new Arc[32], -45, 10);

            //左2
            LwPolyline lw21 = Pus.AddPointsToLwPolyLine(v29, v30, v31, v32, v29);
            LwPolyline lw22 = Pus.AddPointsToLwPolyLine(v35, v34, v33, v30, v31, v32, v35);
            lw22.Vertexes[0].Bulge = Math.Tan(60 * rad / 4);

            fun.AddHatch(dxf, hatching, lw21, new Line[32], new Arc[32], 45, 10);
            fun.AddHatch(dxf, hatching, lw22, new Line[32], new Arc[32], -45, 10);

            //左3
            LwPolyline lw31 = Pus.AddPointsToLwPolyLine(v36, v37, v38, v39, v36);
            LwPolyline lw32 = Pus.AddPointsToLwPolyLine(v42, v41, v40, v37, v38, v39, v42);
            lw32.Vertexes[0].Bulge = Math.Tan(60 * rad / 4);

            fun.AddHatch(dxf, hatching, lw31, new Line[32], new Arc[32], 45, 10);
            fun.AddHatch(dxf, hatching, lw32, new Line[32], new Arc[32], -45, 10);

            //左4
            LwPolyline lw41 = Pus.AddPointsToLwPolyLine(v43, v44, v45, v46, v43);
            LwPolyline lw42 = Pus.AddPointsToLwPolyLine(v49, v48, v47, v44, v45, v46, v49);
            lw42.Vertexes[0].Bulge = Math.Tan(60 * rad / 4);

            fun.AddHatch(dxf, hatching, lw41, new Line[32], new Arc[32], 45, 10);
            fun.AddHatch(dxf, hatching, lw42, new Line[32], new Arc[32], -45, 10);

            #endregion

            #region 标注

            //右
            fun.DimensionLiner(dxf, dimensioning, v1, v2, offset, 0, "b");
            fun.DimensionLiner(dxf, dimensioning, v3, v4, offset, -90, "h2");
            fun.DimensionLiner(dxf, dimensioning, v2, v9, offset * 3, -90, "l1");
            fun.DimensionLiner(dxf, dimensioning, v6, v9, offset * 2, -90, "l2");
            fun.DimensionLiner(dxf, dimensioning, v8, v9, ((v8 - v9) / 2).Y + offset * 2, 180, "a");
            fun.DimensionLiner(dxf, dimensioning, v9, v12, ((v12 - v9) / 2).Y + offset * 2, 180, "f");
            fun.DimensionAligned(dxf, dimensioning, v8, v11, offset, "l3");
            fun.DimensionAngular(dxf, dimensioning, new Line(v9, fun.Polar2(v9, r, 0)), new Line(v9, v8), offset, "75°±1°");
            fun.DimensionRadius(dxf, dimensioning, fun.DrawArc4(fun.Polar2(v9, r, 75), r, fun.Polar2(v9, r, 165), 0), 135, offset, "r");

            fun.jt(dxf, vc1, -105, offset * 0.5, textHeight, "B");
            fun.jt(dxf, vc2, -105, offset * 0.5, textHeight, "B");
            fun.jt(dxf, vc3, -15, offset * 0.5, 1, "A");
            fun.jt(dxf, vc4, -15, offset * 0.5, 1, "A");

            //左1
            fun.DimensionAligned(dxf, dimensioning, v18, v19, -offset, "s");
            fun.DimensionLiner(dxf, dimensioning, v24, v25, -offset, -15, "s");
            fun.DimensionAngular(dxf, dimensioning, new Line(v19, fun.PointRotate(v19, fun.Polar2(v19, r, 74), 6 * rad)), new Line(v19, v22), b + offset, "-6°±1°");
            fun.DimensionAngular(dxf, dimensioning, new Line(v25, fun.PointRotate(v25, fun.Polar2(v25, r, 75), 1 * rad)), new Line(v25, v28), b + offset, "0°±1°");

            Text text1 = new Text("A-A", fun.Polar2((v28 + v22) / 2, offset * 2, 90), textHeight, 0);

            //左2
            fun.DimensionLiner(dxf, dimensioning, v29, v33, -offset * 2, 75, "h1");
            fun.DimensionAngular(dxf, dimensioning, new Line(v29, fun.PointRotate(v29, fun.Polar2(v29, r, -15), 1 * rad)), new Line(v29, fun.Polar2(v29, r, -15)), offset, "0°±1°");

            Text text2 = new Text("B-B", fun.Polar2(v32, offset * 2, 90), textHeight, 0);

            //左3
            fun.DimensionLiner(dxf, dimensioning, v36, v40, -offset * 2, 69, "h1");
            fun.DimensionAngular(dxf, dimensioning, new Line(v36, fun.PointRotate(v36, fun.Polar2(v36, r, -21), 6 * rad)), new Line(v36, fun.Polar2(v36, r, -21)), offset, "-6°±1°");

            //左4

            fun.DimensionLiner(dxf, dimensioning, v43, v47, -offset * 2, 76, "h1");
            fun.DimensionAngular(dxf, dimensioning, new Line(v43, fun.PointRotate(v43, fun.Polar2(v43, r, -9), 5 * rad)), new Line(v43, fun.Polar2(v43, r, -9)), offset, "5°±1°");
            #endregion

            #region 图框

            double isframe = Convert.ToInt32(data["isframe"]);
            String isframe_chose = Convert.ToString(data["isframe_chose"]);
            Vector2 p0 = new Vector2(0, 0);


            if (isframe == 1)
            {
                if (isframe_chose.Equals("0"))
                {
                    Dictionary<string, Vector2> position = Frame.frameA0X(dxf, new Vector2(p0.X - 1189 / 2.0, p0.Y + 841 / 2.0), data);
                    fun.writetext(dxf, scale + ":1", position["比例"], 3.5, 0, 0.6, "C");
                }

                if (isframe_chose.Equals("1"))
                {
                    Dictionary<string, Vector2> position = Frame.frameA1X(dxf, new Vector2(p0.X - 841 / 2.0, p0.Y + 594 / 2.0), data);
                    fun.writetext(dxf, scale + ":1", position["比例"], 3.5, 0, 0.6, "C");
                }

                if (isframe_chose.Equals("2"))
                {
                    Dictionary<string, Vector2> position = Frame.frameA2X(dxf, new Vector2(p0.X - 594 / 2.0, p0.Y + 420 / 2.0), data);
                    fun.writetext(dxf, scale + ":1", position["比例"], 3.5, 0, 0.6, "C");
                }

                if (isframe_chose.Equals("3"))
                {
                    Dictionary<string, Vector2> position = Frame.frameA3X(dxf, new Vector2(p0.X - 420 / 2.0, p0.Y + 297 / 2.0), data);
                    fun.writetext(dxf, scale + ":1", position["比例"], 3.5, 0, 0.6, "C");
                }

                if (isframe_chose.Equals("4X"))
                {
                    Dictionary<string, Vector2> position = Frame.frameA4X(dxf, new Vector2(p0.X - 297 / 2.0, p0.Y + 210 / 2.0 - 10 * 2.26), data);
                    fun.writetext(dxf, scale + ":1", position["比例"], 3.5, 0, 0.6, "C");
                }

                if (isframe_chose.Equals("4Y"))
                {
                    Dictionary<string, Vector2> position = Frame.frameA4Y(dxf, new Vector2(p0.X - 210 / 2.0, p0.Y + 297 / 2.0), data);
                    fun.writetext(dxf, scale + ":1", position["比例"], 3.5, 0, 0.6, "C");
                }
            }

            #endregion

            #region 编辑

            //添加图层
            fun.AddEntities(dxf, contour, line01, lw01, lw02, lw03, lw11, lw12, lw13, lw14, lw21, lw22, lw31, lw32, lw41, lw42);
            fun.AddEntities(dxf, center, lc01, lc02);
            fun.AddEntities(dxf, textlayer, text1, text2);



            //设置跟随图层
            fun.SetByLayer(dxf);

            #endregion

            dxf.DrawingVariables.AcadVer = DxfVersion.AutoCad2007;
            dxf.Save(path);


        }

        public static void StyleS_InsertS(Dictionary<string, Object> data)
        {
            DxfDocument dxf = new DxfDocument();
            Layer contour = new Layer("contour") { Color = AciColor.Cyan };    //1,轮廓层
            Layer cutting = new Layer("cutting") { Color = AciColor.Red };    //切削层

            string path = Convert.ToString(data["path"]);
            //参数名称取自ISO 5610-2
            double b = 12;
            double l1 = 90;
            double l2 = 32;
            double f = 16;
            double l3 = 9.525;
            double h2 = 12;
            double h1 = 12;
            double s = 3.97;
            double insertAngle = 90 * pi / 180;
            double alphan = 7 * pi / 180;
            double cutagl = 45 * pi / 180;
            double lambdas = 0;
            double gammao = 0;
            double repsilon = 0;
            #region
            try
            {
                if (data["re"] != null)
                    repsilon = Convert.ToDouble(data["re"]);
                if (repsilon <= 0)
                    repsilon = 0.01;
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["lams"] != null)
                    lambdas = Convert.ToDouble(data["lams"]) * pi / 180;
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["gamo"] != null)
                    gammao = Convert.ToDouble(data["gamo"]) * pi / 180;
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["b"] != null)
                    b = Convert.ToDouble(data["b"]);
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["s"] != null)
                    s = Convert.ToDouble(data["s"]);
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["lf"] != null)
                    l1 = Convert.ToDouble(data["lf"]);
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["lh"] != null)
                    l2 = Convert.ToDouble(data["lh"]);
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["wf"] != null)
                    f = Convert.ToDouble(data["wf"]);
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["h"] != null)
                    h2 = Convert.ToDouble(data["h"]);
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["hf"] != null)
                    h1 = Convert.ToDouble(data["hf"]);
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["epsr"] != null)
                    insertAngle = Convert.ToDouble(data["epsr"]) * pi / 180;
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["kapr"] != null)
                    cutagl = Convert.ToDouble(data["kapr"]) * pi / 180;
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["an"] != null)
                    alphan = Convert.ToDouble(data["an"]) * pi / 180;
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["ic"] != null)
                    l3 = Pus.GetLByIC(Convert.ToDouble(data["ic"]), insertAngle);
            }
            catch (KeyNotFoundException) { }
            #endregion
            double kscale = 1;
            if (l1 >= 120)
                kscale = 1;
            else
                kscale = 1.5;
            double lineWidth = 1;
            //k点位置恒定
            Vector3 k = new Vector3(0, 0, 0);
            RectShank rs = new RectShank(b, l1, f, l2, l3, 4, false, insertAngle, cutagl, lambdas, false, gammao, alphan, s, repsilon);
            Vector3[] shank = rs.Shank;
            Vector3[] inserts = rs.Inserts;
            //线性变换
            double theta = 0 * pi / 180;
            Matrix3 linearTrans = new Matrix3(
                Math.Cos(theta) * kscale, -Math.Sin(theta) * kscale, 0,
                Math.Sin(theta) * kscale, Math.Cos(theta) * kscale, 0,
                              0, 0, kscale
            );
            for (int i = 0; i < shank.Length; i++)
            {
                shank[i] = linearTrans * shank[i];
            }
            for (int i = 0; i < inserts.Length; i++)
            {
                inserts[i] = linearTrans * inserts[i];
            }

            //刀头部分
            Vector3[] head = new Vector3[11];
            Face3d fb = new Face3d(shank[1], shank[2], shank[3]);
            Face3d fbk = new Face3d(shank[1], shank[5], shank[6]);
            Face3d ff = new Face3d(shank[0], shank[3], shank[4]);
            Face3d fiu = new Face3d(inserts[4], inserts[5], inserts[6]);
            Vector3 nbu = Pus.UnitVector(shank[0], shank[4]);
            int icp = inserts.Length / 2;
            head[0] = Pus.Inters(fb, inserts[3], inserts[3] + nbu);
            head[1] = Pus.Inters(fb, inserts[0], inserts[0] + nbu);
            Face3d fd0 = new Face3d(inserts[0], inserts[3], head[0]);
            Face3d ft = new Face3d(inserts[0], head[1], new Vector3(shank[7].X, shank[7].Y - kscale * 1.5, shank[7].Z));
            head[5] = Pus.Inters(ft, inserts[4], inserts[5]);
            Face3d fcon = new Face3d(shank[2], shank[6], shank[7]);
            head[2] = Pus.Inters(fcon, Pus.Inters(ft, fb, head[1]));
            head[3] = shank[3];
            head[6] = Pus.Inters(fcon, Pus.Inters(ft, fiu, head[5]));
            head[7] = shank[7];
            Face3d fd1 = new Face3d(inserts[3], head[0], inserts[2]);
            head[10] = Pus.Inters(fd1, inserts[5], inserts[6]);
            head[4] = Pus.Inters(fbk, Pus.Inters(fb, fd1, head[0]));
            head[9] = Pus.Inters(fbk, Pus.Inters(fiu, fd1, head[10]));
            head[8] = Pus.Inters(fiu, shank[2], shank[6]);



            //mview
            LwPolyline msk = Pus.AddPointsToLwPolyLine(shank[4], shank[5], shank[6], shank[7]);
            msk.IsClosed = true;
            fun.PolyFill(dxf, msk, lineWidth, contour);

            LwPolyline mhd = Pus.AddPointsToLwPolyLine(head[5], head[6], head[7], head[8], head[9], head[10], inserts[5]);
            mhd.IsClosed = true;
            fun.PolyFill(dxf, mhd, lineWidth, contour);

            LwPolyline mist = Pus.AddPointsToLwPolyLine(inserts[4], inserts[5], inserts[6], inserts[7]);
            mist.IsClosed = true;
            Pus.AglToArc(mist, repsilon);
            fun.PolyFill(dxf, mist, lineWidth, cutting);


            //mview标注
            DimensionStyle dimensionStyle = new DimensionStyle("mystyle");
            dimensionStyle.ArrowSize = kscale * 1.5;
            dimensionStyle.DimArrow1 = DimensionArrowhead.Closedfilled;
            dimensionStyle.DimArrow2 = DimensionArrowhead.Closedfilled;
            dimensionStyle.TextHeight = kscale * 1.5;
            dimensionStyle.TextOffset = kscale;
            double offset = 7 * kscale;
            LinearDimension dim_b = new LinearDimension(new Line(shank[5], shank[4]), offset, Pus.Degree(shank[5], shank[4]), dimensionStyle);
            fun.dxflinedim(dxf, dim_b, b);
            LinearDimension dim_f = new LinearDimension(new Line(Vector3.Zero, head[8]), Vector2.Distance(Vector2.Zero, Pus.ToV2(head[8])) / 2 + offset, Pus.Degree(shank[4], shank[5]), dimensionStyle);
            fun.dxflinedim(dxf, dim_f, f);
            LinearDimension dim_l1 = new LinearDimension(new Line(Vector3.Zero, shank[4]), b / 2 * kscale, 180, dimensionStyle);
            fun.dxflinedim(dxf, dim_l1, l1);
            LinearDimension dim_l2 = new LinearDimension(new Line(shank[6], Pus.ReferenceV3(Pus.GetArcFromPline(mist, 4).Center, -repsilon, 0, 0)), Vector2.Distance(Pus.ToV2(inserts[7]), Pus.ToV2(head[8])) / 3, 0, dimensionStyle);
            fun.dxflinedim(dxf, dim_l2, l2);
            Angular2LineDimension dim_cutagl = new Angular2LineDimension(new Line(inserts[4], inserts[7]),
                new Line(Pus.ToV2(inserts[4]), fun.Polar(Pus.ToV2(inserts[4]), pi, 1)), offset, dimensionStyle);
            dim_cutagl.UserText = Math.Round(cutagl * 180 / pi, 1) + "°";
            dxf.AddEntity(dim_cutagl);

            //zview
            //绕y轴旋转pi/2再平移得到左视图
            Vector3[] zshank = new Vector3[shank.Length];
            Vector3[] zhead = new Vector3[head.Length];
            Vector3[] zinserts = new Vector3[inserts.Length];
            Vector3 zviewMkr = new Vector3(0, 1, 0);
            double yR = pi / 2;
            double zoffset = -2 * b * kscale;
            for (int i = 0; i < shank.Length; i++)
            {
                zshank[i] = Pus.Rodrigue(zviewMkr, 1, yR, shank[i]);
                zshank[i].X += zoffset;
            }
            for (int i = 0; i < inserts.Length; i++)
            {
                zinserts[i] = Pus.Rodrigue(zviewMkr, 1, yR, inserts[i]);
                zinserts[i].X += zoffset;
            }
            for (int i = 0; i < head.Length; i++)
            {
                zhead[i] = Pus.Rodrigue(zviewMkr, 1, yR, head[i]);
                zhead[i].X += zoffset;
            }
            Vector3 zk = k;
            zk.X += zoffset;
            LwPolyline zfd0 = Pus.AddPointsToLwPolyLine(zhead[0], zhead[1], zinserts[0], zinserts[3]);
            zfd0.IsClosed = true;
            fun.PolyFill(dxf, zfd0, lineWidth, contour);
            LwPolyline zfd1 = Pus.AddPointsToLwPolyLine(zinserts[3], zhead[0], zhead[4], zhead[9], zhead[10]);
            fun.PolyFill(dxf, zfd1, lineWidth, contour);


            LwPolyline zist0 = Pus.AddPointsToLwPolyLine(zinserts[0], zinserts[4], zinserts[7], zinserts[3]);
            zist0.IsClosed = true;
            fun.PolyFill(dxf, zist0, lineWidth, cutting);
            LwPolyline zist1 = Pus.AddPointsToLwPolyLine(zinserts[3], zinserts[7], zinserts[6], zinserts[2]);
            zist1.IsClosed = true;
            fun.PolyFill(dxf, zist1, lineWidth, cutting);

            if (zinserts[7].X < zinserts[5].X)
            {
                LwPolyline zfiu = Pus.AddPointsToLwPolyLine(zinserts[5], zhead[5], zhead[6], zhead[8], zhead[9], zhead[10]);
                zfiu.IsClosed = true;
                fun.PolyFill(dxf, zfiu, lineWidth, contour);

                LwPolyline zistu = Pus.AddPointsToLwPolyLine(zinserts[4], zinserts[5], zinserts[6], zinserts[7]);
                zistu.IsClosed = true;
                fun.PolyFill(dxf, zistu, lineWidth, cutting);
            }
            //zview标注
            LinearDimension dim_h1 = new LinearDimension(new Line(zk, zhead[1]), offset * 0.7, Pus.Degree(zshank[4], zshank[0]), dimensionStyle);
            fun.dxflinedim(dxf, dim_h1, h1);

            Vector2 z4 = Pus.ToV2(zinserts[4]);
            if (lambdas == 0)
            {
                lambdas = 0.1 * pi / 180;
                Pus.NeedleDim(dxf, new Line(z4, fun.Polar(z4, -pi / 2, 1)),
                    new Line(z4, fun.Polar(z4, -pi / 2 + lambdas, 1)), offset * 1.7, "λs=0°", dimensionStyle);
            }
            else
            {
                Pus.NeedleDim(dxf, new Line(z4, fun.Polar(z4, -pi / 2, 1)),
                    new Line(z4, fun.Polar(z4, -pi / 2 + lambdas, 1)), offset * 1.7, "λs=" + Math.Round(lambdas * 180 / pi, 2) + "°", dimensionStyle);
            }

            //lview
            Vector3[] lshank = new Vector3[shank.Length];
            Vector3[] linserts = new Vector3[inserts.Length];
            Vector3[] lhead = new Vector3[head.Length];
            //放倒
            Vector3 laydown = new Vector3(-1, 0, 0);
            double laydownR = pi / 2;
            double loffset = -h2 * 2 * kscale;
            for (int i = 0; i < shank.Length; i++)
            {
                lshank[i] = Pus.Rodrigue(laydown, 1, laydownR, shank[i]);
                lshank[i].Y += loffset;
            }

            for (int i = 0; i < inserts.Length; i++)
            {
                linserts[i] = Pus.Rodrigue(laydown, 1, laydownR, inserts[i]);
                linserts[i].Y += loffset;
            }

            for (int i = 0; i < head.Length; i++)
            {
                lhead[i] = Pus.Rodrigue(laydown, 1, laydownR, head[i]);
                lhead[i].Y += loffset;
            }
            Vector3 lk = k;
            lk.Y += loffset;

            LwPolyline lsk = Pus.AddPointsToLwPolyLine(lshank[0], lshank[4], lshank[7], lshank[3]);
            lsk.IsClosed = true;
            fun.PolyFill(dxf, lsk, lineWidth, contour);

            LwPolyline lft = Pus.AddPointsToLwPolyLine(lhead[1], lhead[2], lhead[6], lhead[5]);
            fun.PolyFill(dxf, lft, lineWidth, contour);
            LwPolyline lfd0 = Pus.AddPointsToLwPolyLine(lhead[0], lhead[1], linserts[0], linserts[3]);
            lfd0.IsClosed = true;
            fun.PolyFill(dxf, lfd0, lineWidth, contour);

            LwPolyline list0 = Pus.AddPointsToLwPolyLine(linserts[0], linserts[4], linserts[7], linserts[3]);
            list0.IsClosed = true;
            fun.PolyFill(dxf, list0, lineWidth, cutting);

            if (linserts[6].Y > linserts[4].Y)
            {
                LwPolyline lfiu = Pus.AddPointsToLwPolyLine(lhead[5], lhead[6], lhead[8], lhead[9], lhead[10], linserts[5]);
                lfiu.IsClosed = true;
                fun.PolyFill(dxf, lfiu, lineWidth, contour);

                LwPolyline listu = Pus.AddPointsToLwPolyLine(linserts[4], linserts[5], linserts[6], linserts[7]);
                listu.IsClosed = true;
                fun.PolyFill(dxf, listu, lineWidth, cutting);

            }
            //lview标注
            Vector2 list7 = Pus.ToV2(linserts[7]);
            if (gammao == 0)
            {
                gammao = 0.1 * pi / 180;
                Pus.NeedleDim(dxf, new Line(linserts[6], linserts[7]),
                    new Line(list7, fun.Polar(list7, Pus.AngleOnP(linserts[6], linserts[7]) + gammao, 1)), offset * 1.3, "γn=0°", dimensionStyle);
            }
            else
            {
                Pus.NeedleDim(dxf, new Line(linserts[6], linserts[7]),
                    new Line(list7, fun.Polar(list7, Pus.AngleOnP(linserts[6], linserts[7]) + gammao, 1)), offset, "γn=" + Math.Round(gammao * 180 / pi, 2) + "°", dimensionStyle);
            }
            LinearDimension dim_h2 = new LinearDimension(new Line(lshank[4], lshank[0]), offset, Pus.Degree(lshank[4], lshank[0]), dimensionStyle);
            fun.dxflinedim(dxf, dim_h2, h2);


            //图框
            Vector2 a3xsize = Frame.A3X;
            double isframe = 0;
            try
            {
                isframe = Convert.ToDouble(data["isframe"]);
            }
            catch (KeyNotFoundException) { }
            if (isframe != 0)
            {
                Vector2 EntitysCenter = new Vector2((shank[4].X + zhead[0].X) / 2, (shank[4].Y + lshank[0].Y) / 2);
                Vector2 p0 = new Vector2(EntitysCenter.X - a3xsize.X / 2, EntitysCenter.Y + a3xsize.Y / 2);
                Dictionary<string, Vector2> positions = Frame.frameA3X(dxf, p0);
                Vector2 kp = p0;
                try
                {
                    kp = positions["比例"];
                    fun.writetextofC(dxf, kscale + ":1", positions["比例"], 3.5, 0, 0.6, 3);
                }
                catch (Exception) { }
            }

            dxf.DrawingVariables.AcadVer = DxfVersion.AutoCad2007;
            dxf.Save(path);
        }
        public static void StyleS_InsertR(Dictionary<string, Object> data)
        {
            DxfDocument dxf = new DxfDocument();
            Layer contour = new Layer("contour") { Color = AciColor.Cyan };    //1,轮廓层
            Layer cutting = new Layer("cutting") { Color = AciColor.Red };    //切削层

            string path = Convert.ToString(data["path"]);
            double pi = Math.PI;
            //参数名称取自ISO 5610-2
            double b = 8;
            double d = 6;
            double l1 = 70;
            double l2 = 25;
            double f = 10;
            double l3 = 9.525;
            double h2 = 8;
            double h1 = 8;
            double s = 2.38;
            double alphan = 7 * pi / 180;
            double lambdas = 0;
            double gamao = 0;
            double repsilon = 0;
            #region 13399中的参数名称与之对应
            try
            {
                if (data["re"] != null)
                    repsilon = Convert.ToDouble(data["re"]);
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["lams"] != null)
                    lambdas = Convert.ToDouble(data["lams"]) * pi / 180;
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["gamo"] != null)
                    gamao = Convert.ToDouble(data["gamo"]) * pi / 180;
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["b"] != null)
                    b = Convert.ToDouble(data["b"]);
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["ic"] != null)
                    d = Convert.ToDouble(data["ic "]);
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["s"] != null)
                    s = Convert.ToDouble(data["s"]);
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["l"] != null)
                    l3 = Convert.ToDouble(data["l"]);
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["lf"] != null)
                    l1 = Convert.ToDouble(data["lf"]);
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["lh"] != null)
                    l2 = Convert.ToDouble(data["lh"]);
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["wf"] != null)
                    f = Convert.ToDouble(data["wf"]);
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["h"] != null)
                    h2 = Convert.ToDouble(data["h"]);
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["hf"] != null)
                    h1 = Convert.ToDouble(data["hf"]);
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["an"] != null)
                    alphan = Convert.ToDouble(data["an"]) * pi / 180;
            }
            catch (KeyNotFoundException) { }
            Dictionary<double, double> l3_repsilon = new Dictionary<double, double> {
                { 6.4,0.4},
                { 9.525,0.8},
                { 12.7,0.8},
                { 15.875,1.2},
                { 19.05,1.2},
                { 25.4,2.4},
            };
            #endregion
            //俯视图
            Vector2 c0 = new Vector2(0, 0);
            Vector2 c1 = c0;
            Vector2 c2 = new Vector2(c1.X, c1.Y + b);
            Vector2 c3 = new Vector2(c2.X - l1 + l2, c2.Y);
            Vector2 c5 = new Vector2(c3.X, c1.Y);
            Vector2 insertCen = new Vector2(c1.X - l1 + d / 2, c3.Y - f + d / 2);
            Circle insert = new Circle(insertCen, d / 2);
            fun.drawcircle(dxf, insertCen, d / 2, 0.1, cutting);
            //偏移后的刀片底部外轮廓
            double insert_offset = s * Math.Tan(alphan);
            Circle buttom_insert = new Circle(insertCen, d / 2 - insert_offset);
            //切点q1,q2
            Vector2 q1 = fun.Polar(insertCen, 1.5 * pi, buttom_insert.Radius);
            Vector2 q2 = fun.Polar(insertCen, 0.75 * pi, buttom_insert.Radius);
            Vector2 c4 = fun.Inters(q1, new Vector2(q1.X + 1, q1.Y + 1), c2, c3);
            Vector2 x2 = LineXCir(insert, c4, q2)[1];
            Vector2 c6 = new Vector2(c5.X - 2, q1.Y);
            Vector2 x1 = LineXCir(insert, q1, c6)[1];
            LwPolyline pline = AddPointsToLwPolyLine(x1, c6, c5, c1, c2, c3, c4, x2);
            fun.PolyFill(dxf, pline, 0.1, contour);
            DrawPlineByTwoPoints(dxf, c3, c5, contour);
            DimensionStyle dimensionStyle = fun.CreateDimStyle();
            dimensionStyle.ArrowSize = 0.2;
            dimensionStyle.DimArrow1 = DimensionArrowhead.Closedfilled;
            dimensionStyle.DimArrow2 = DimensionArrowhead.Closedfilled;
            dimensionStyle.TextHeight = 0.5;
            double offset = 7;
            Vector2 cir1 = new Vector2(c1.X - l1, insertCen.Y);
            Vector2 cir2 = new Vector2(insertCen.X, insertCen.Y - d / 2);
            Vector2 cir3 = new Vector2(insertCen.X, insertCen.Y + d / 2);
            LinearDimension dim_l1 = new LinearDimension(new Line(cir1, c1), 1.5 * offset, -180, dimensionStyle);
            fun.dxflinedim(dxf, dim_l1, l1);
            LinearDimension dim_l2 = new LinearDimension(new Line(cir1, c5), offset, -180, dimensionStyle);
            fun.dxflinedim(dxf, dim_l2, l2);
            LinearDimension dim_b = new LinearDimension(new Line(c2, c1), offset, -90, dimensionStyle);
            fun.dxflinedim(dxf, dim_b, b);
            LinearDimension dim_f = new LinearDimension(new Line(cir2, c4), offset * 2, 90, dimensionStyle);
            fun.dxflinedim(dxf, dim_f, f);
            LinearDimension dim_d = new LinearDimension(new Line(cir3, cir2), offset * 0.7, 90, dimensionStyle);
            fun.dxflinedim(dxf, dim_d, d);
            //主视图
            Vector2 m1 = new Vector2(c1.X, c2.Y + offset);
            Vector2 m2 = new Vector2(m1.X, m1.Y + h2);
            Vector2 m3 = new Vector2(c5.X, m2.Y);
            //刀片上第二个弧的结束点的x坐标小于x1的坐标
            Vector2 m4 = new Vector2(x1.X, m1.Y + h1);
            Vector2 m5 = new Vector2(cir1.X, m4.Y);
            Vector2 m6 = new Vector2(cir1.X + insert_offset, m5.Y - s);
            Vector2 m7 = new Vector2(q1.X, m4.Y - s);
            Vector2 m8 = new Vector2(m6.X, m1.Y);
            Vector2 m9 = new Vector2(c6.X, m1.Y + h2);
            Vector2 m10 = new Vector2(c6.X, m1.Y);
            Vector2 m11 = new Vector2(m3.X, m1.Y);
            LwPolyline polylineM = AddPointsToLwPolyLine(m6, m8, m1, m2, m4, m7);
            fun.PolyFill(dxf, polylineM, 0.1, contour);
            LwPolyline insertM = AddPointsToLwPolyLine(m4, m5, m6, m7);
            fun.PolyFill(dxf, insertM, 0.1, cutting);
            DrawPlineByTwoPoints(dxf, m3, m11);
            DrawPlineByTwoPoints(dxf, m9, m10);
            //主视图标注
            LinearDimension dim_h2 = new LinearDimension(new Line(m1, m2), offset, -90, dimensionStyle);
            fun.dxflinedim(dxf, dim_h2, h2);
            LinearDimension dim_h1 = new LinearDimension(new Line(m5, m8), offset * 1.5, 90, dimensionStyle);
            fun.dxflinedim(dxf, dim_h1, h1);
            LinearDimension dim_s = new LinearDimension(new Line(m5, m6), offset * 0.7, 90, dimensionStyle);
            fun.dxflinedim(dxf, dim_s, s);
            Angular2LineDimension dim_alphan = new Angular2LineDimension(new Line(m5, new Vector2(m5.X - 1, m5.Y)), new Line(m5, m6), 1, dimensionStyle);
            dim_alphan.UserText = alphan * 180 / pi + "°" + "+90°";
            dim_alphan.SetDimensionLinePosition(new Vector2(m5.X - 3, m5.Y - 3));
            dxf.AddEntity(dim_alphan);
            ////左视图
            Vector2 z3 = new Vector2(m1.X + offset * 3, m1.Y);
            Vector2 z4 = new Vector2(z3.X, z3.Y + h2);
            Vector2 z1 = new Vector2(z3.X + c4.Y - q1.Y, z3.Y + h1 - s);
            Vector2 z2 = new Vector2(z1.X, z3.Y);
            Vector2 z5 = new Vector2(z3.X + c2.Y - x2.Y, z3.Y + h1);
            Vector2 z6 = new Vector2(z3.X + c2.Y - cir2.Y, z5.Y);
            Vector2 z7 = new Vector2(z3.X + c2.Y - q2.Y, z1.Y);
            LwPolyline zPline = AddPointsToLwPolyLine(z1, z2, z3, z4, z5, z7);
            fun.PolyFill(dxf, zPline, 0.1, contour);
            LwPolyline zCutting = AddPointsToLwPolyLine(z5, z6, z1, z7);
            fun.PolyFill(dxf, zCutting, 0.1, cutting);
            //左视图标注
            LinearDimension dim_zs = new LinearDimension(new Line(z1, z6), offset * 0.6, -90, dimensionStyle);
            fun.dxflinedim(dxf, dim_zs, s);
            Angular2LineDimension dim_alphan_z = new Angular2LineDimension(new Line(z1, z6), new Line(z6, new Vector2(z6.X + 1, z6.Y)), 1, dimensionStyle);
            dim_alphan_z.UserText = alphan * 180 / pi + "°" + "+90°";
            dim_alphan_z.SetDimensionLinePosition(new Vector2(z6.X + 4, z6.Y - 4));
            dxf.AddEntity(dim_alphan_z);
            dxf.DrawingVariables.AcadVer = DxfVersion.AutoCad2007;
            dxf.Save(path);
        }
        //V型刀头 横小
        public static void StyleV_InsertV(Dictionary<string, Object> data)
        {
            DxfDocument dxf = new DxfDocument();
            Layer contour = new Layer("contour") { Color = AciColor.Cyan };    //1,轮廓层
            Layer cutting = new Layer("cutting") { Color = AciColor.Red };    //切削层

            string path = Convert.ToString(data["path"]);
            //参数名称取自ISO 5610-2
            double b = 12;
            double l1 = 70;
            double l2 = 25;
            double f = 6;
            double l3 = 11.1;
            double h2 = 12;
            double h1 = 12;
            double s = 3.18;
            double insertAngle = 35 * pi / 180;
            double alphan = 7 * pi / 180;
            double cutagl = 72.5 * pi / 180;
            double lambdas = 0;
            double gammao = 0;
            double repsilon = 0;
            #region
            try
            {
                if (data["re"] != null)
                    repsilon = Convert.ToDouble(data["re"]);
                if (repsilon <= 0)
                    repsilon = 0.01;
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["lams"] != null)
                    lambdas = Convert.ToDouble(data["lams"]) * pi / 180;
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["gamo"] != null)
                    gammao = Convert.ToDouble(data["gamo"]) * pi / 180;
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["b"] != null)
                    b = Convert.ToDouble(data["b"]);
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["s"] != null)
                    s = Convert.ToDouble(data["s"]);
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["lf"] != null)
                    l1 = Convert.ToDouble(data["lf"]);
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["lh"] != null)
                    l2 = Convert.ToDouble(data["lh"]);
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["wf"] != null)
                    f = Convert.ToDouble(data["wf"]);
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["h"] != null)
                    h2 = Convert.ToDouble(data["h"]);
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["hf"] != null)
                    h1 = Convert.ToDouble(data["hf"]);
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["epsr"] != null)
                    insertAngle = Convert.ToDouble(data["epsr"]) * pi / 180;
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["kapr"] != null)
                    cutagl = Convert.ToDouble(data["kapr"]) * pi / 180;
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["an"] != null)
                    alphan = Convert.ToDouble(data["an"]) * pi / 180;
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["ic"] != null)
                    l3 = Pus.GetLByIC(Convert.ToDouble(data["ic"]), insertAngle);
            }
            catch (KeyNotFoundException) { }
            #endregion
            double kscale = 1;
            if (l1 >= 120)
                kscale = 1;
            else
                kscale = 1.5;
            double lineWidth = 1;
            //k点位置恒定
            Vector3 k = new Vector3(0, 0, 0);
            RectShank rs = new RectShank(b, l1, f, l2, l3, 4, true, insertAngle, cutagl, lambdas, true, gammao, alphan, s, repsilon);
            Vector3[] shank = rs.Shank;
            Vector3[] inserts = rs.Inserts;
            int icp = rs.InsertShape;
            //线性变换
            double theta = 0 * pi / 180;
            Matrix3 linearTrans = new Matrix3(
                Math.Cos(theta) * kscale, -Math.Sin(theta) * kscale, 0,
                Math.Sin(theta) * kscale, Math.Cos(theta) * kscale, 0,
                              0, 0, kscale
            );
            for (int i = 0; i < shank.Length; i++)
            {
                shank[i] = linearTrans * shank[i];
            }
            for (int i = 0; i < inserts.Length; i++)
            {
                inserts[i] = linearTrans * inserts[i];
            }
            repsilon *= kscale;

            Vector3[] head = new Vector3[7];
            Face3d fiu = new Face3d(inserts[icp + 1], inserts[icp + 2], inserts[icp + 3]);
            Face3d fb = new Face3d(shank[0], shank[1], shank[2]);
            Face3d ff = new Face3d(shank[0], shank[4], shank[7]);
            Face3d fbk = new Face3d(shank[1], shank[2], shank[6]);
            Face3d fc0 = new Face3d(shank[2], shank[3], shank[7]);
            Vector3 nx = inserts[icp] - inserts[0];
            Vector3 nbu = shank[4] - shank[0];
            head[0] = Pus.Inters(fb, inserts[0], inserts[0] + nx);
            Face3d fd0 = new Face3d(inserts[0], head[0], inserts[1]);
            Face3d fd1 = new Face3d(inserts[0], head[0], inserts[icp - 1]);
            head[1] = Pus.Inters(fd0, shank[0], shank[3]);
            head[2] = Pus.Inters(fd1, shank[1], shank[2]);
            head[3] = Pus.Inters(fiu, Pus.Inters(fd0, ff, head[1]));
            head[4] = Pus.Inters(fiu, shank[3], shank[7]);
            head[5] = Pus.Inters(fiu, shank[2], shank[6]);
            Face3d fc1 = new Face3d(head[1], head[2], head[3]);
            head[6] = Pus.Inters(fiu, Pus.Inters(fd1, fbk, head[2]));


            //mview
            LwPolyline msk = Pus.AddPointsToLwPolyLine(shank[4], shank[5], shank[6], shank[7]);
            msk.IsClosed = true;
            fun.PolyFill(dxf, msk, lineWidth, contour);

            LwPolyline mfiu = Pus.AddPointsToLwPolyLine(inserts[2 * icp - 1], inserts[icp + 2], inserts[icp + 1], head[3], head[4], head[5], head[6]);
            mfiu.IsClosed = true;
            fun.PolyFill(dxf, mfiu, lineWidth, contour);

            LwPolyline mist = new LwPolyline();
            for (int i = icp; i < icp * 2; i++)
            {
                Pus.AddPointsToLwPolyLine(mist, inserts[i]);
            }
            mist.IsClosed = true;
            Pus.AglToArc(mist, repsilon);
            fun.PolyFill(dxf, mist, lineWidth, cutting);

            //mview标注
            DimensionStyle dimensionStyle = new DimensionStyle("mystyle");
            dimensionStyle.ArrowSize = kscale * 1.5;
            dimensionStyle.DimArrow1 = DimensionArrowhead.Closedfilled;
            dimensionStyle.DimArrow2 = DimensionArrowhead.Closedfilled;
            dimensionStyle.TextHeight = kscale * 1.5;
            dimensionStyle.TextOffset = kscale;
            double offset = 7 * kscale;
            LinearDimension dim_b = new LinearDimension(new Line(shank[5], shank[4]), offset, Pus.Degree(shank[5], shank[4]), dimensionStyle);
            fun.dxflinedim(dxf, dim_b, b);
            LinearDimension dim_f = new LinearDimension(new Line(Vector3.Zero, shank[6]), shank[6].X / 2 + offset, Pus.Degree(shank[4], shank[5]), dimensionStyle);
            fun.dxflinedim(dxf, dim_f, f);
            LinearDimension dim_l1 = new LinearDimension(new Line(Vector3.Zero, shank[4]), Math.Abs(shank[4].Y) + offset, 180, dimensionStyle);
            fun.dxflinedim(dxf, dim_l1, l1);
            LinearDimension dim_l2 = new LinearDimension(new Line(shank[6], Vector3.Zero), Math.Abs(shank[6].Y) + offset, 0, dimensionStyle);
            fun.dxflinedim(dxf, dim_l2, l2);
            Angular2LineDimension dim_cutagl = new Angular2LineDimension(new Line(inserts[icp], inserts[icp + 1]),
                new Line(Pus.ToV2(inserts[icp]), fun.Polar(Pus.ToV2(inserts[icp]), -pi / 2, 1)), offset, dimensionStyle);
            dim_cutagl.UserText = Math.Round(cutagl * 180 / pi, 1) + "°";
            dxf.AddEntity(dim_cutagl);

            //zview
            //绕y轴旋转pi/2再平移得到左视图
            Vector3[] zshank = new Vector3[shank.Length];
            Vector3[] zhead = new Vector3[head.Length];
            Vector3[] zinserts = new Vector3[inserts.Length];
            Vector3 zviewMkr = new Vector3(0, 1, 0);
            double yR = pi / 2;
            double zoffset = -2 * b * kscale;
            for (int i = 0; i < shank.Length; i++)
            {
                zshank[i] = Pus.Rodrigue(zviewMkr, 1, yR, shank[i]);
                zshank[i].X += zoffset;
            }
            for (int i = 0; i < inserts.Length; i++)
            {
                zinserts[i] = Pus.Rodrigue(zviewMkr, 1, yR, inserts[i]);
                zinserts[i].X += zoffset;
            }
            for (int i = 0; i < head.Length; i++)
            {
                zhead[i] = Pus.Rodrigue(zviewMkr, 1, yR, head[i]);
                zhead[i].X += zoffset;
            }
            Vector3 zk = k;
            zk.X += zoffset;

            LwPolyline zfd1 = Pus.AddPointsToLwPolyLine(zinserts[0], zhead[0], zhead[2], zhead[6], zinserts[2 * icp - 1]);
            fun.PolyFill(dxf, zfd1, lineWidth, contour);

            LwPolyline zfd0 = Pus.AddPointsToLwPolyLine(zinserts[0], zhead[0], zhead[1], zhead[3], zinserts[icp + 1]);
            fun.PolyFill(dxf, zfd0, lineWidth, contour);

            LwPolyline zist0 = Pus.AddPointsToLwPolyLine(zinserts[0], zinserts[icp], zinserts[icp + 1], zinserts[1]);
            zist0.IsClosed = true;
            fun.PolyFill(dxf, zist0, lineWidth, cutting);

            LwPolyline zist1 = Pus.AddPointsToLwPolyLine(zinserts[0], zinserts[icp], zinserts[icp * 2 - 1], zinserts[icp - 1]);
            zist1.IsClosed = true;
            fun.PolyFill(dxf, zist1, lineWidth, cutting);

            if (zinserts[icp + 2].X > zinserts[icp].X)
            {
                LwPolyline zfiu = Pus.AddPointsToLwPolyLine(zinserts[icp + 1], zhead[3], zhead[4], zhead[5], zhead[6], zinserts[icp * 2 - 1]);
                fun.PolyFill(dxf, zfiu, lineWidth, contour);

                LwPolyline zist = new LwPolyline();
                for (int i = icp; i < icp * 2; i++)
                {
                    Pus.AddPointsToLwPolyLine(zist, zinserts[i]);
                }
                zist.IsClosed = true;
                fun.PolyFill(dxf, zist, lineWidth, cutting);
            }

            //zview标注
            Vector2 zicp = Pus.ToV2(zinserts[icp]);
            if (gammao == 0)
            {
                gammao = 0.1 * pi / 180;
                Pus.NeedleDim(dxf, new Line(zicp, fun.Polar(zicp, -pi / 2, 1)),
                    new Line(zicp, fun.Polar(zicp, -pi / 2 + gammao, 1)), offset * 1.7, "γo=0°", dimensionStyle);
            }
            else
            {
                Pus.NeedleDim(dxf, new Line(zicp, fun.Polar(zicp, -pi / 2, 1)),
                    new Line(zicp, fun.Polar(zicp, -pi / 2 + gammao, 1)), offset * 1.7, "γo=" + Math.Round(gammao * 180 / pi, 2) + "°", dimensionStyle);
            }

            //lview
            Vector3[] lshank = new Vector3[shank.Length];
            Vector3[] linserts = new Vector3[inserts.Length];
            Vector3[] lhead = new Vector3[head.Length];
            //放倒
            Vector3 laydown = new Vector3(-1, 0, 0);
            double laydownR = pi / 2;
            double loffset = -h2 * 2 * kscale;
            for (int i = 0; i < shank.Length; i++)
            {
                lshank[i] = Pus.Rodrigue(laydown, 1, laydownR, shank[i]);
                lshank[i].Y += loffset;
            }

            for (int i = 0; i < inserts.Length; i++)
            {
                linserts[i] = Pus.Rodrigue(laydown, 1, laydownR, inserts[i]);
                linserts[i].Y += loffset;
            }

            for (int i = 0; i < head.Length; i++)
            {
                lhead[i] = Pus.Rodrigue(laydown, 1, laydownR, head[i]);
                lhead[i].Y += loffset;
            }
            Vector3 lk = k;
            lk.Y += loffset;

            LwPolyline lff = Pus.AddPointsToLwPolyLine(lshank[0], lshank[4], lshank[7], lhead[4], lhead[3], lhead[1]);
            lff.IsClosed = true;
            fun.PolyFill(dxf, lff, lineWidth, contour);

            LwPolyline lfd0 = Pus.AddPointsToLwPolyLine(linserts[0], lhead[0], lhead[1], lhead[3], linserts[icp + 1]);
            fun.PolyFill(dxf, lfd0, lineWidth, contour);

            LwPolyline list0 = Pus.AddPointsToLwPolyLine(linserts[0], linserts[icp], linserts[icp + 1], linserts[1]);
            list0.IsClosed = true;
            fun.PolyFill(dxf, list0, lineWidth, cutting);

            if (linserts[2 * icp - 1].Y > linserts[icp + 1].Y)
            {
                LwPolyline lfiu = Pus.AddPointsToLwPolyLine(linserts[icp + 1], lhead[3], lhead[4], lhead[5], lhead[6], linserts[icp * 2 - 1]);
                fun.PolyFill(dxf, lfiu, lineWidth, contour);

                LwPolyline listu = new LwPolyline();
                for (int i = icp; i < icp * 2; i++)
                {
                    Pus.AddPointsToLwPolyLine(listu, linserts[i]);
                }
                listu.IsClosed = true;
                fun.PolyFill(dxf, listu, lineWidth, cutting);

            }

            //lview标注
            Vector2 licp = Pus.ToV2(linserts[icp]);
            if (lambdas == 0)
            {
                lambdas = 0.1 * pi / 180;
                Pus.NeedleDim(dxf, new Line(linserts[icp + 1], linserts[icp]),
                    new Line(licp, fun.Polar(licp, Pus.AngleOnP(linserts[icp + 1], linserts[icp]) + lambdas, 1)), offset * 1.5, "λs=0°", dimensionStyle);
            }
            else
            {
                Pus.NeedleDim(dxf, new Line(linserts[icp + 1], linserts[icp]),
                    new Line(licp, fun.Polar(licp, Pus.AngleOnP(linserts[icp + 1], linserts[icp]) + lambdas, 1)), offset * 1.5, "λs=" + Math.Round(lambdas * 180 / pi, 2) + "°", dimensionStyle);
            }

            LinearDimension dim_h1 = new LinearDimension(new Line(lhead[0], lk), offset, Pus.Degree(lshank[0], lshank[4]), dimensionStyle);
            fun.dxflinedim(dxf, dim_h1, h1);
            LinearDimension dim_h2 = new LinearDimension(new Line(lshank[4], lshank[0]), offset, Pus.Degree(lshank[4], lshank[0]), dimensionStyle);
            fun.dxflinedim(dxf, dim_h2, h2);

            //图框
            Vector2 a3xsize = Frame.A3X;
            double isframe = 0;
            try
            {
                isframe = Convert.ToDouble(data["isframe"]);
            }
            catch (KeyNotFoundException) { }
            if (isframe != 0)
            {
                Vector2 EntitysCenter = new Vector2((shank[4].X + zhead[0].X) / 2, (shank[4].Y + lshank[0].Y) / 2);
                Vector2 p0 = new Vector2(EntitysCenter.X - a3xsize.X / 2, EntitysCenter.Y + a3xsize.Y / 2);
                Dictionary<string, Vector2> positions = Frame.frameA3X(dxf, p0);
                Vector2 kp = p0;
                try
                {
                    kp = positions["比例"];
                    fun.writetextofC(dxf, kscale + ":1", positions["比例"], 3.5, 0, 0.6, 3);
                }
                catch (Exception) { }
            }

            dxf.DrawingVariables.AcadVer = DxfVersion.AutoCad2007;
            dxf.Save(path);
        }
        //D型刀头 横小
        public static void StyleD_InsertS(Dictionary<string, Object> data)
        {
            DxfDocument dxf = new DxfDocument();
            Layer contour = new Layer("contour") { Color = AciColor.Cyan };    //1,轮廓层
            Layer cutting = new Layer("cutting") { Color = AciColor.Red };    //切削层

            string path = Convert.ToString(data["path"]);
            //参数名称取自ISO 5610-4
            double b = 12;
            double l1 = 70;
            double l2 = 32;
            double f = 6;
            double l3 = 9.52;
            double h2 = 12;
            double h1 = 12;
            double s = 3.18;
            double insertAngle = 90 * pi / 180;
            double alphan = 0 * pi / 180;
            double cutagl = 45 * pi / 180;
            double lambdas = 0;
            double gammao = 0;
            double repsilon = 0;
            #region
            try
            {
                if (data["re"] != null)
                    repsilon = Convert.ToDouble(data["re"]);
                if (repsilon <= 0)
                    repsilon = 0.01;
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["lams"] != null)
                    lambdas = Convert.ToDouble(data["lams"]) * pi / 180;
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["gamo"] != null)
                    gammao = Convert.ToDouble(data["gamo"]) * pi / 180;
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["b"] != null)
                    b = Convert.ToDouble(data["b"]);
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["s"] != null)
                    s = Convert.ToDouble(data["s"]);
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["lf"] != null)
                    l1 = Convert.ToDouble(data["lf"]);
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["lh"] != null)
                    l2 = Convert.ToDouble(data["lh"]);
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["wf"] != null)
                    f = Convert.ToDouble(data["wf"]);
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["h"] != null)
                    h2 = Convert.ToDouble(data["h"]);
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["hf"] != null)
                    h1 = Convert.ToDouble(data["hf"]);
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["epsr"] != null)
                    insertAngle = Convert.ToDouble(data["epsr"]) * pi / 180;
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["kapr"] != null)
                    cutagl = Convert.ToDouble(data["kapr"]) * pi / 180;
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["an"] != null)
                    alphan = Convert.ToDouble(data["an"]) * pi / 180;
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["l"] != null)
                    l3 = Convert.ToDouble(data["l"]);
            }
            catch (KeyNotFoundException) { }
            #endregion
            double kscale = 1;
            if (l1 >= 120)
                kscale = 1;
            else
                kscale = 1.5;
            double lineWidth = 1;
            //k点位置恒定
            Vector3 k = new Vector3(0, 0, 0);
            //刀杆柄部模型
            Vector3[] shank = new Vector3[8];
            shank[4] = new Vector3(k.X + l1, k.Y + f - b, k.Z);
            shank[5] = new Vector3(shank[4].X, shank[4].Y + b, shank[4].Z);
            shank[6] = new Vector3(k.X + l2, shank[5].Y, shank[5].Z);
            shank[7] = new Vector3(shank[6].X, shank[4].Y, shank[6].Z);
            shank[0] = Pus.ToV3(shank[4], shank[4].Z - h2);
            shank[1] = Pus.ToV3(shank[5], shank[5].Z - h2);
            shank[2] = Pus.ToV3(shank[6], shank[6].Z - h2);
            shank[3] = Pus.ToV3(shank[7], shank[7].Z - h2);

            //横向进给，主偏角小于90°：i4 = fun.polar(K,kapr-pi,r(1/tan(epsr/2)-1/tan((pi-karp)/2)))
            Vector2 icorner = fun.Polar(Vector2.Zero, pi / 2 + cutagl, repsilon * (1 / Math.Tan(insertAngle / 2) - 1 / Math.Tan((pi - cutagl) / 2)));
            //刀片的上表面
            Vector2[] inserts2d = Pus.DiamondPoints(icorner, l3, insertAngle, true, cutagl);
            double insertOffset = Math.Tan(alphan) * s;
            //刀片下表面
            Vector2[] inserts2dd = Pus.OffsetPoints(insertOffset, inserts2d);
            //刀片模型
            Vector3[] inserts = new Vector3[inserts2d.Length * 2];
            for (int i = 0; i < inserts2d.Length; i++)
            {
                inserts[i] = Pus.ToV3(inserts2dd[i], k.Z - s);
                inserts[i + inserts2d.Length] = Pus.ToV3(inserts2d[i], k.Z);
            }
            //线性变换
            double theta = 0 * pi / 180;
            Matrix3 linearTrans = new Matrix3(
                Math.Cos(theta) * kscale, -Math.Sin(theta) * kscale, 0,
                Math.Sin(theta) * kscale, Math.Cos(theta) * kscale, 0,
                              0, 0, kscale
            );
            for (int i = 0; i < shank.Length; i++)
            {
                shank[i] = linearTrans * shank[i];
            }
            for (int i = 0; i < inserts.Length; i++)
            {
                inserts[i] = linearTrans * inserts[i];
            }
            //放倒
            Vector3 laydownV = new Vector3(-1, 0, 0);
            double laydownR = pi / 2;
            for (int i = 0; i < shank.Length; i++)
            {
                shank[i] = Pus.Rodrigue(laydownV, 1, laydownR, shank[i]);
            }
            for (int i = 0; i < inserts.Length; i++)
            {
                inserts[i] = Pus.Rodrigue(laydownV, 1, laydownR, inserts[i]);
            }

            //先创建lambdas
            //从k点到主切削刃
            Vector3 mainCutEdgeO = Pus.UnitVector(inserts[4], inserts[5]);
            Vector3 lambdasMkr = Pus.Rodrigue(new Vector3(0, 1, 0), 1, pi / 2, mainCutEdgeO);
            for (int i = 0; i < inserts.Length; i++)
            {
                inserts[i] = Pus.Rodrigue(lambdasMkr, 1, lambdas, inserts[i]);
            }
            //创建gammao
            //变化之后的主切削刃单位向量就是产生gammao的向量
            Vector3 gammaoMkr = Pus.UnitVector(inserts[5], inserts[4]);
            for (int i = 0; i < inserts.Length; i++)
            {
                inserts[i] = Pus.Rodrigue(gammaoMkr, 1, Math.Atan(Math.Cos(lambdas) * Math.Tan(gammao)), inserts[i]);
            }

            //刀头部分
            Vector3[] head = new Vector3[13];
            Face3d fb = new Face3d(shank[1], shank[2], shank[3]);
            Face3d fbk = new Face3d(shank[1], shank[5], shank[6]);
            Face3d ff = new Face3d(shank[0], shank[3], shank[4]);
            Face3d fiu = new Face3d(inserts[4], inserts[5], inserts[6]);
            Vector3 nbu = Pus.UnitVector(shank[0], shank[4]);
            int icp = inserts.Length / 2;
            head[5] = Pus.KPoint(inserts[icp + 1], inserts[icp + 2], 0.05);
            head[12] = Pus.KPoint(inserts[icp + 2], inserts[icp + 3], 0.95);

            head[0] = Pus.Inters(fb, inserts[0], inserts[4]);
            Face3d fd0 = new Face3d(head[0], inserts[0], head[5]);
            head[1] = Pus.Inters(ff, Pus.Inters(fd0, fb, head[0]));
            head[6] = Pus.Inters(ff, Pus.Inters(fd0, fiu, head[5]));
            Face3d fd1 = new Face3d(head[0], inserts[0], head[12]);
            head[4] = Pus.Inters(fbk, Pus.Inters(fd1, fb, head[0]));
            head[11] = Pus.Inters(fbk, Pus.Inters(fiu, fd1, head[12]));

            head[2] = shank[3];
            head[3] = shank[2];
            head[8] = shank[7];
            head[9] = shank[6];
            Face3d fcon = new Face3d(head[8], head[9], shank[2]);
            head[7] = Pus.Inters(fcon, Pus.Inters(fiu, ff, head[6]));
            head[10] = Pus.Inters(fcon, Pus.Inters(fiu, fbk, head[11]));

            //立正
            Vector3[] mshank = new Vector3[shank.Length];
            Vector3[] mhead = new Vector3[head.Length];
            Vector3[] minserts = new Vector3[inserts.Length];
            for (int i = 0; i < shank.Length; i++)
            {
                mshank[i] = Pus.Rodrigue(laydownV, 1, -laydownR, shank[i]);
            }
            for (int i = 0; i < inserts.Length; i++)
            {
                minserts[i] = Pus.Rodrigue(laydownV, 1, -laydownR, inserts[i]);
            }
            for (int i = 0; i < head.Length; i++)
            {
                mhead[i] = Pus.Rodrigue(laydownV, 1, -laydownR, head[i]);
            }
            //mview
            LwPolyline msk = Pus.AddPointsToLwPolyLine(mshank[4], mshank[5], mshank[6], mshank[7]);
            msk.IsClosed = true;
            fun.PolyFill(dxf, msk, lineWidth, contour);

            LwPolyline mcon = Pus.AddPointsToLwPolyLine(mhead[10], mhead[7]);
            fun.PolyFill(dxf, mcon, lineWidth, contour);

            LwPolyline mhd = Pus.AddPointsToLwPolyLine(mhead[8], mhead[9], mhead[10], mhead[11], mhead[12], minserts[6], mhead[5], mhead[6], mhead[7]);
            mhd.IsClosed = true;
            fun.PolyFill(dxf, mhd, lineWidth, contour);

            LwPolyline mist = Pus.AddPointsToLwPolyLine(minserts[4], minserts[5], minserts[6], minserts[7]);
            mist.IsClosed = true;
            fun.PolyFill(dxf, mist, lineWidth, cutting);
            //mview标注
            DimensionStyle dimensionStyle = new DimensionStyle("mystyle");
            dimensionStyle.ArrowSize = kscale * 1.5;
            dimensionStyle.DimArrow1 = DimensionArrowhead.Closedfilled;
            dimensionStyle.DimArrow2 = DimensionArrowhead.Closedfilled;
            dimensionStyle.TextHeight = kscale * 1.5;
            dimensionStyle.TextOffset = kscale / 2;
            double offset = 7 * kscale;
            LinearDimension dim_f = new LinearDimension(new Line(Vector3.Zero, mhead[11]), offset * 1.5, Pus.Degree(mshank[4], mshank[5]), dimensionStyle);
            fun.dxflinedim(dxf, dim_f, f);
            LinearDimension dim_l1 = new LinearDimension(new Line(Vector3.Zero, mshank[4]), offset * 1.5, 180, dimensionStyle);
            fun.dxflinedim(dxf, dim_l1, l1);
            LinearDimension dim_l2 = new LinearDimension(new Line(mshank[6], Vector3.Zero), offset * 1.5, 0, dimensionStyle);
            fun.dxflinedim(dxf, dim_l2, l2);
            Angular2LineDimension dim_cutagl = new Angular2LineDimension(new Line(minserts[4], minserts[5]),
                new Line(Pus.ToV2(minserts[4]), fun.Polar(Pus.ToV2(minserts[4]), -pi / 2, 1)), offset, dimensionStyle);
            dim_cutagl.UserText = Math.Round(cutagl * 180 / pi, 1) + "°";
            dxf.AddEntity(dim_cutagl);

            //zview
            //绕y轴旋转pi/2再平移得到左视图
            Vector3[] zshank = new Vector3[shank.Length];
            Vector3[] zhead = new Vector3[head.Length];
            Vector3[] zinserts = new Vector3[inserts.Length];
            Vector3 zviewMkr = new Vector3(0, 1, 0);
            double yR = pi / 2;
            double zoffset = -2 * b * kscale;
            for (int i = 0; i < shank.Length; i++)
            {
                zshank[i] = Pus.Rodrigue(zviewMkr, 1, yR, mshank[i]);
                zshank[i].X += zoffset;
            }
            for (int i = 0; i < inserts.Length; i++)
            {
                zinserts[i] = Pus.Rodrigue(zviewMkr, 1, yR, minserts[i]);
                zinserts[i].X += zoffset;
            }
            for (int i = 0; i < head.Length; i++)
            {
                zhead[i] = Pus.Rodrigue(zviewMkr, 1, yR, mhead[i]);
                zhead[i].X += zoffset;
            }
            Vector3 zk = k;
            zk.X += zoffset;
            LwPolyline zhd;
            if (zinserts[6].X > zinserts[4].X)
            {
                zhd = Pus.AddPointsToLwPolyLine(zinserts[0], zhead[0], zhead[1], zhead[6], zhead[5], zinserts[6], zhead[12], zhead[11], zhead[4], zhead[0]);
                LwPolyline fiul = Pus.AddPointsToLwPolyLine(zhead[11], zhead[10], zhead[7], zhead[6]);
                fun.PolyFill(dxf, fiul, lineWidth, contour);
            }
            else
            {
                zhd = Pus.AddPointsToLwPolyLine(zhead[12], zhead[11], zhead[4], zhead[0], zinserts[0], zhead[0], zhead[1], zhead[6], zhead[5]);
            }
            fun.PolyFill(dxf, zhd, lineWidth, contour);

            LwPolyline zist = Pus.AddPointsToLwPolyLine(zinserts[7], zinserts[4], zinserts[5]);
            if (zinserts[6].X > zinserts[4].X)
            {
                Pus.AddPointsToLwPolyLine(zist, zinserts[6], zinserts[7]);
            }
            fun.PolyFill(dxf, zist, lineWidth, cutting);
            LwPolyline zlen = Pus.AddPointsToLwPolyLine(zinserts[7], zinserts[3], zinserts[0], zinserts[4], zinserts[0], zinserts[1], zinserts[5]);
            fun.PolyFill(dxf, zlen, lineWidth, cutting);
            //zview标注
            if (gammao == 0)
            {
                gammao = 0.1 * pi / 180;
                Pus.NeedleDim(dxf, new Line(zinserts[4], zinserts[7]),
                    new Line(Pus.ToV2(zinserts[4]), fun.Polar(Pus.ToV2(zinserts[4]), Pus.AngleOnP(zinserts[4], zinserts[7]) - gammao, 1)), offset * 1.5, "γo=0°", dimensionStyle);
            }
            else
            {
                Pus.NeedleDim(dxf, new Line(zinserts[4], zinserts[7]),
                    new Line(Pus.ToV2(zinserts[4]), fun.Polar(Pus.ToV2(zinserts[4]), Pus.AngleOnP(zinserts[4], zinserts[7]) - gammao, 1)), offset * 1.5, "γo=" + Math.Round(gammao * 180 / pi, 2) + "°", dimensionStyle);
            }


            //lview
            double lviewOffset = -h2 * 2 * kscale;
            Vector3[] lshank = new Vector3[shank.Length];
            for (int i = 0; i < shank.Length; i++)
            {
                lshank[i] = new Vector3(shank[i].X, shank[i].Y + lviewOffset, shank[i].Z);
            }
            Vector3[] linserts = new Vector3[inserts.Length];
            for (int i = 0; i < inserts.Length; i++)
            {
                linserts[i] = new Vector3(inserts[i].X, inserts[i].Y + lviewOffset, inserts[i].Z);
            }
            Vector3[] lhead = new Vector3[head.Length];
            for (int i = 0; i < head.Length; i++)
            {
                lhead[i] = new Vector3(head[i].X, head[i].Y + lviewOffset, head[i].Z);
            }
            Vector3 lk = k;
            lk.Y += lviewOffset;
            LwPolyline ffl = Pus.AddPointsToLwPolyLine(lshank[0], lshank[4], lshank[7], lhead[8], lhead[7], lhead[6], lhead[1]);
            ffl.IsClosed = true;
            fun.PolyFill(dxf, ffl, lineWidth, contour);
            LwPolyline fd0l = Pus.AddPointsToLwPolyLine(linserts[0], lhead[0], lhead[1], lhead[6], lhead[5]);
            fun.PolyFill(dxf, fd0l, lineWidth, contour);
            LwPolyline list = Pus.AddPointsToLwPolyLine(linserts[0], linserts[1], linserts[5], linserts[4]);
            list.IsClosed = true;
            fun.PolyFill(dxf, list, lineWidth, cutting);
            LwPolyline fconl = Pus.AddPointsToLwPolyLine(lhead[7], lhead[8], lhead[9], lhead[10]);
            fconl.IsClosed = true;
            fun.PolyFill(dxf, fconl, lineWidth, contour);
            if (lhead[11].Y > lhead[6].Y)
            {
                LwPolyline fiul = Pus.AddPointsToLwPolyLine(linserts[6], lhead[5], lhead[6], lhead[7], lhead[10], lhead[11], lhead[12]);
                fiul.IsClosed = true;
                fun.PolyFill(dxf, fiul, lineWidth, contour);
                LwPolyline listu = Pus.AddPointsToLwPolyLine(linserts[4], linserts[5], linserts[6], linserts[7]);
                listu.IsClosed = true;
                fun.PolyFill(dxf, listu, lineWidth, cutting);
            }
            //lview标注
            if (lambdas == 0)
            {
                lambdas = 0.1 * pi / 180;
                Pus.NeedleDim(dxf, new Line(Pus.ToV2(linserts[4]), fun.Polar(Pus.ToV2(linserts[4]), pi, 1)),
                    new Line(Pus.ToV2(linserts[4]), fun.Polar(Pus.ToV2(linserts[4]), pi - lambdas, 1)), offset, "λs=0°", dimensionStyle);
            }
            else
            {
                Pus.NeedleDim(dxf, new Line(Pus.ToV2(linserts[4]), fun.Polar(Pus.ToV2(linserts[4]), pi, 1)),
                    new Line(Pus.ToV2(linserts[4]), fun.Polar(Pus.ToV2(linserts[4]), pi - lambdas, 1)), offset, "λs=" + Math.Round(lambdas * 180 / pi, 2) + "°", dimensionStyle);
            }
            LinearDimension dim_h2 = new LinearDimension(new Line(lshank[4], lshank[0]), offset, Pus.Degree(lshank[4], lshank[0]), dimensionStyle);
            fun.dxflinedim(dxf, dim_h2, h2);
            LinearDimension dim_h1 = new LinearDimension(new Line(lhead[0], lk), offset * 0.5, Pus.Degree(lshank[0], lshank[4]), dimensionStyle);
            fun.dxflinedim(dxf, dim_h1, h1);



            //图框
            Vector2 a3xsize = Frame.A3X;
            double isframe = 0;
            try
            {
                isframe = Convert.ToDouble(data["isframe"]);
            }
            catch (KeyNotFoundException) { }
            if (isframe != 0)
            {
                Vector2 EntitysCenter = new Vector2((mshank[4].X + zhead[0].X) / 2, (mshank[4].Y + lshank[0].Y) / 2);
                Vector2 p0 = new Vector2(EntitysCenter.X - a3xsize.X / 2, EntitysCenter.Y + a3xsize.Y / 2);
                Dictionary<string, Vector2> positions = Frame.frameA3X(dxf, p0);
                Vector2 kp = p0;
                try
                {
                    kp = positions["比例"];
                    fun.writetextofC(dxf, kscale + ":1", positions["比例"], 3.5, 0, 0.6, 3);
                }
                catch (Exception) { }
            }

            dxf.DrawingVariables.AcadVer = DxfVersion.AutoCad2007;
            dxf.Save(path);
        }
        public static void StyleD_InsertR(Dictionary<string, Object> data)
        {
            DxfDocument dxf = new DxfDocument();
            Layer contour = new Layer("contour") { Color = AciColor.Cyan };    //1,轮廓层
            Layer cutting = new Layer("cutting") { Color = AciColor.Red };    //切削层

            string path = Convert.ToString(data["path"]);
            //参数名称取自ISO 5610-4
            double b = 8;
            double l1 = 70;
            double l2 = 15;
            double d = 6;
            double f = 4;
            double h2 = 8;
            double h1 = 8;
            double s = 2.38;
            double alphan = 0 * pi / 180;
            double lambdas = 0;
            double gammao = 0;
            double repsilon = 0;
            #region
            try
            {
                if (data["re"] != null)
                    repsilon = Convert.ToDouble(data["re"]);
                if (repsilon <= 0)
                    repsilon = 0.01;
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["lams"] != null)
                    lambdas = Convert.ToDouble(data["lams"]) * pi / 180;
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["b"] != null)
                    b = Convert.ToDouble(data["b"]);
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["ic"] != null)
                    d = Convert.ToDouble(data["ic"]);
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["s"] != null)
                    s = Convert.ToDouble(data["s"]);
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["lf"] != null)
                    l1 = Convert.ToDouble(data["lf"]);
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["lh"] != null)
                    l2 = Convert.ToDouble(data["lh"]);
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["wf"] != null)
                    f = Convert.ToDouble(data["wf"]);
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["h"] != null)
                    h2 = Convert.ToDouble(data["h"]);
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["hf"] != null)
                    h1 = Convert.ToDouble(data["hf"]);
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["an"] != null)
                    alphan = Convert.ToDouble(data["an"]) * pi / 180;
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["an"] != null)
                    gammao = Convert.ToDouble(data["gamo"]) * pi / 180;
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["an"] != null)
                    lambdas = Convert.ToDouble(data["lams"]) * pi / 180;
            }
            catch (KeyNotFoundException) { }
            #endregion
            double kscale = 1;
            if (l1 >= 120)
                kscale = 1;
            else
                kscale = 1.5;
            double lineWidth = 1;
            //k点位置恒定
            Vector3 k = new Vector3(0, 0, 0);
            RectShank rs = new RectShank(b, l1, f, l2, double.NaN, 4, true, double.NaN, double.NaN, lambdas, true, double.NaN, alphan, s, repsilon);
            Vector3[] shank = rs.Shank;
            //线性变换
            double theta = 0 * pi / 180;
            Matrix3 linearTrans = new Matrix3(
                Math.Cos(theta) * kscale, -Math.Sin(theta) * kscale, 0,
                Math.Sin(theta) * kscale, Math.Cos(theta) * kscale, 0,
                              0, 0, kscale
            );
            for (int i = 0; i < shank.Length; i++)
            {
                shank[i] = linearTrans * shank[i];
            }
            d *= kscale;

            //mview
            LwPolyline msk = Pus.AddPointsToLwPolyLine(shank[4], shank[5], shank[6], shank[7]);
            msk.IsClosed = true;
            Pus.LightFillPline(dxf, msk, lineWidth, contour);

            EntityObject roundInsert = RectShank.RoundInsert(d / 2, gammao);
            List<Vector2> ev2s;//从圆或椭圆实体中获取的点,它们是以原点为中心的;
            List<Vector2> v2s = new List<Vector2>();//偏移后的点的容器
            LwPolyline insertPline;
            int precision = 100;
            if (gammao == 0)
            {
                Circle c = (Circle)roundInsert;
                ev2s = c.PolygonalVertexes(precision);
                for (int i = 0; i < precision; i++)
                {
                    v2s.Add(new Vector2(ev2s[i].X + d / 2, ev2s[i].Y));
                }
                insertPline = Pus.AddPointsToLwPolyLine(v2s);

                LwPolyline p1 = Pus.AddPointsToLwPolyLine(new Vector2(d / 2, d / 2), fun.Polar(new Vector2(d / 2, d / 2), 3 * pi / 180, 1.5 * d), Pus.ToV2(shank[6]));
                p1.Vertexes[1].Bulge = Math.Tan(10 * pi / 180);
                fun.PolyFill(dxf, p1, lineWidth, contour);
                LwPolyline p2 = Pus.AddPointsToLwPolyLine(new Vector2(d / 2, -d / 2), fun.Polar(new Vector2(d / 2, -d / 2), -3 * pi / 180, 1.5 * d), Pus.ToV2(shank[7]));
                p2.Vertexes[1].Bulge = Math.Tan(-10 * pi / 180);
                fun.PolyFill(dxf, p2, lineWidth, contour);
            }
            else
            {
                Ellipse e = (Ellipse)roundInsert;
                ev2s = e.PolygonalVertexes(precision);
                for (int i = 0; i < precision; i++)
                {
                    v2s.Add(new Vector2(ev2s[i].X + d / 2 * Math.Cos(gammao), ev2s[i].Y));
                }
                insertPline = Pus.AddPointsToLwPolyLine(v2s);

                LwPolyline p1 = Pus.AddPointsToLwPolyLine(new Vector2(d / 2, d / 2), fun.Polar(new Vector2(d / 2, d / 2), 3 * pi / 180, 1.5 * d), Pus.ToV2(shank[6]));
                p1.Vertexes[1].Bulge = Math.Tan(10 * pi / 180);
                fun.PolyFill(dxf, p1, lineWidth, contour);
                LwPolyline p2 = Pus.AddPointsToLwPolyLine(new Vector2(d / 2, -d / 2), fun.Polar(new Vector2(d / 2, -d / 2), -3 * pi / 180, 1.5 * d), Pus.ToV2(shank[7]));
                p2.Vertexes[1].Bulge = Math.Tan(-10 * pi / 180);
                fun.PolyFill(dxf, p2, lineWidth, contour);
            }
            insertPline.IsClosed = true;
            Pus.LightFillPline(dxf, insertPline, lineWidth, cutting);

            //mview标注
            DimensionStyle dimensionStyle = new DimensionStyle("mystyle");
            dimensionStyle.ArrowSize = kscale * 1.5;
            dimensionStyle.DimArrow1 = DimensionArrowhead.Closedfilled;
            dimensionStyle.DimArrow2 = DimensionArrowhead.Closedfilled;
            dimensionStyle.TextHeight = kscale * 1.5;
            dimensionStyle.TextOffset = kscale;
            double offset = 7 * kscale;
            LinearDimension dim_b = new LinearDimension(new Line(shank[5], shank[4]), offset, Pus.Degree(shank[5], shank[4]), dimensionStyle);
            fun.dxflinedim(dxf, dim_b, b);
            LinearDimension dim_f = new LinearDimension(new Line(Vector3.Zero, shank[6]), shank[6].X / 2 + offset, Pus.Degree(shank[4], shank[5]), dimensionStyle);
            fun.dxflinedim(dxf, dim_f, f);
            LinearDimension dim_l1 = new LinearDimension(new Line(Vector3.Zero, shank[4]), Math.Abs(shank[4].Y) + offset, 180, dimensionStyle);
            fun.dxflinedim(dxf, dim_l1, l1);
            LinearDimension dim_l2 = new LinearDimension(new Line(shank[6], Vector3.Zero), Math.Abs(shank[6].Y) + offset, 0, dimensionStyle);
            fun.dxflinedim(dxf, dim_l2, l2);

            //zview
            //绕y轴旋转pi/2再平移得到左视图
            Vector3[] zshank = new Vector3[shank.Length];
            Vector3 zviewMkr = new Vector3(0, 1, 0);
            double yR = pi / 2;
            double zoffset = -2 * b * kscale;
            for (int i = 0; i < shank.Length; i++)
            {
                zshank[i] = Pus.Rodrigue(zviewMkr, 1, yR, shank[i]);
                zshank[i].X += zoffset;
            }
            Vector3 zk = k;
            zk.X += zoffset;

            LwPolyline z1 = Pus.AddPointsToLwPolyLine(zshank[6], zshank[7], zshank[3], zshank[2]);
            z1.IsClosed = true;
            fun.PolyFill(dxf, z1, lineWidth, contour);

            Vector2 cen = Pus.ToV2(Pus.KPoint(zshank[6], zshank[7], 0.5));
            Vector2 zd1 = fun.Polar(cen, -pi / 2, d / 2);
            Vector2 zd2 = fun.Polar(zd1, pi, zshank[4].X - zshank[0].X);
            Vector2 zd3 = fun.Polar(zd2, pi / 2, d);
            Vector2 zd4 = fun.Polar(zd3, 0, zshank[4].X - zshank[0].X);
            LwPolyline z2 = Pus.AddPointsToLwPolyLine(zd1, zd2, zd3, zd4);
            z2.IsClosed = true;
            fun.PolyFill(dxf, z2, lineWidth, contour);
            Vector2 zi1 = zd1;
            Vector2 zi2 = fun.Polar(zi1, pi - alphan, s / Math.Cos(alphan));
            Vector2 zi4 = zd4;
            Vector2 zi3 = fun.Polar(zi4, pi + alphan, s / Math.Cos(alphan));
            LwPolyline z3 = Pus.AddPointsToLwPolyLine(zi1, zi2, zi3, zi4);
            z3.IsClosed = true;
            fun.PolyFill(dxf, z3, lineWidth, cutting);

            //lview
            Vector3[] lshank = new Vector3[shank.Length];
            //放倒
            Vector3 laydown = new Vector3(-1, 0, 0);
            double laydownR = pi / 2;
            double loffset = -h2 * 2 * kscale;
            for (int i = 0; i < shank.Length; i++)
            {
                lshank[i] = Pus.Rodrigue(laydown, 1, laydownR, shank[i]);
                lshank[i].Y += loffset;
            }
            Vector3 lk = k;
            lk.Y += loffset;

            LwPolyline lsk = Pus.AddPointsToLwPolyLine(lshank[0], lshank[4], lshank[7], lshank[3]);
            lsk.IsClosed = true;
            fun.PolyFill(dxf, lsk, lineWidth, contour);

            Vector2 lhd1 = new Vector2(d / 2, lshank[7].Y);
            Vector2 lhd2 = new Vector2(s * Math.Tan(alphan), lshank[3].Y);
            Vector2 lhd3 = fun.Polar(lhd2, pi / 2, (h1 - s) * kscale);
            LwPolyline lhd = Pus.AddPointsToLwPolyLine(lhd1, Pus.ToV2(lshank[7]), Pus.ToV2(lshank[3]), lhd2, lhd3);
            fun.PolyFill(dxf, lhd, lineWidth, contour);

            Vector2 li1 = new Vector2(0, lshank[7].Y);
            Vector2 li2 = lhd1;
            Vector2 li3 = fun.Polar(li2, -pi / 2, s * kscale);
            Vector2 li4 = lhd3;
            LwPolyline li = Pus.AddPointsToLwPolyLine(li1, li2, li3, li4);
            li.IsClosed = true;
            fun.PolyFill(dxf, li, lineWidth, cutting);

            //LinearDimension dim_h1 = new LinearDimension(new Line(lhead[0], lk), offset, Pus.Degree(lshank[0], lshank[4]), dimensionStyle);
            //fun.dxflinedim(dxf, dim_h1, h1);
            LinearDimension dim_h2 = new LinearDimension(new Line(lshank[4], lshank[0]), offset, Pus.Degree(lshank[4], lshank[0]), dimensionStyle);
            fun.dxflinedim(dxf, dim_h2, h2);

            //图框
            Vector2 a3xsize = Frame.A3X;
            double isframe = 0;
            try
            {
                isframe = Convert.ToDouble(data["isframe"]);
            }
            catch (KeyNotFoundException) { }
            if (isframe != 0)
            {
                Vector2 EntitysCenter = new Vector2((shank[4].X + zshank[0].X) / 2, (shank[4].Y + lshank[0].Y) / 2);
                Vector2 p0 = new Vector2(EntitysCenter.X - a3xsize.X / 2, EntitysCenter.Y + a3xsize.Y / 2);
                Dictionary<string, Vector2> positions = Frame.frameA3X(dxf, p0);
                Vector2 kp = p0;
                try
                {
                    kp = positions["比例"];
                    fun.writetextofC(dxf, kscale + ":1", positions["比例"], 3.5, 0, 0.6, 3);
                }
                catch (Exception) { }
            }

            dxf.DrawingVariables.AcadVer = DxfVersion.AutoCad2007;
            dxf.Save(path);
        }
        //G型刀头 横大
        /*        public static void StyleG_InsertC(Dictionary<string, Object> data)
                {
                    DxfDocument dxf = new DxfDocument();
                    Layer contour = new Layer("contour") { Color = AciColor.Cyan };    //1,轮廓层
                    Layer cutting = new Layer("cutting") { Color = AciColor.Red };    //切削层

                    string path = Convert.ToString(data["path"]);
                    double pi = Math.PI;
                    //参数名称取自ISO 5610-4
                    double b = 8;
                    double l1 = 100;
                    double l2 = 12;
                    double f = 10;
                    double l3 = 6.4;
                    double h2 = 8;
                    double h1 = 8;
                    double s = 2.38;
                    double insertAngle = 80 * pi / 180;
                    double alphan = 7 * pi / 180;
                    double cutagl = 90 * pi / 180;
                    double lambdas = 0;
                    double gamao = 0;
                    double repsilon = 0;
                    #region
                    try
                    {
                        if (data["re"] != null)
                            repsilon = Convert.ToDouble(data["re"]);
                        if (repsilon <= 0)
                            repsilon = 0.01;
                    }
                    catch (KeyNotFoundException) { }
                    try
                    {
                        if (data["lams"] != null)
                            lambdas = Math.Abs(Convert.ToDouble(data["lams"]) * pi / 180);
                    }
                    catch (KeyNotFoundException) { }
                    try
                    {
                        if (data["gamo"] != null)
                            gamao = Math.Abs(Convert.ToDouble(data["gamo"]) * pi / 180);
                    }
                    catch (KeyNotFoundException) { }
                    try
                    {
                        if (data["b"] != null)
                            b = Convert.ToDouble(data["b"]);
                    }
                    catch (KeyNotFoundException) { }
                    try
                    {
                        if (data["s"] != null)
                            s = Convert.ToDouble(data["s"]);
                    }
                    catch (KeyNotFoundException) { }
                    try
                    {
                        if (data["lf"] != null)
                            l1 = Convert.ToDouble(data["lf"]);
                    }
                    catch (KeyNotFoundException) { }
                    try
                    {
                        if (data["lh"] != null)
                            l2 = Convert.ToDouble(data["lh"]);
                    }
                    catch (KeyNotFoundException) { }
                    try
                    {
                        if (data["wf"] != null)
                            f = Convert.ToDouble(data["wf"]);
                    }
                    catch (KeyNotFoundException) { }
                    try
                    {
                        if (data["h"] != null)
                            h2 = Convert.ToDouble(data["h"]);
                    }
                    catch (KeyNotFoundException) { }
                    try
                    {
                        if (data["hf"] != null)
                            h1 = Convert.ToDouble(data["hf"]);
                    }
                    catch (KeyNotFoundException) { }
                    try
                    {
                        if (data["epsr"] != null)
                            insertAngle = Convert.ToDouble(data["epsr"]) * pi / 180;
                    }
                    catch (KeyNotFoundException) { }
                    try
                    {
                        if (data["kapr"] != null)
                            cutagl = Convert.ToDouble(data["kapr"]) * pi / 180;
                    }
                    catch (KeyNotFoundException) { }
                    try
                    {
                        if (data["an"] != null)
                            alphan = Convert.ToDouble(data["an"]) * pi / 180;
                    }
                    catch (KeyNotFoundException) { }
                    try
                    {
                        if (data["l"] != null)
                            l3 = Convert.ToDouble(data["l"]);
                    }
                    catch (KeyNotFoundException) { }
                    #endregion
                    double kscale = 1;
                    if (l1 >= 120)
                        kscale = 1;
                    else
                        kscale = 1.5;
                    double lineWidth = 1;
                    //k点位置恒定
                    Vector3 k = new Vector3(0, 0, 0);
                    Vector3 b2 = new Vector3(k.X + l1, k.Y + f, k.Z - h1);
                    Vector3 b1 = new Vector3(b2.X, b2.Y - b, b2.Z);
                    Vector3 b6 = new Vector3(k.X + l2, b1.Y, b1.Z);

                    //刀杆顶面
                    Vector3 u1 = new Vector3(b1.X, b1.Y, b1.Z + h2);
                    Vector3 u2 = new Vector3(b2.X, b2.Y, b2.Z + h2);
                    Vector3 u3 = new Vector3(b6.X, b2.Y, b2.Z + h2);
                    double guai = kscale;
                    Vector3 u3p = new Vector3(u3.X - guai, u3.Y, u3.Z);
                    Vector3 u4 = new Vector3(b6.X, b6.Y, b6.Z + h2);
                    Vector3 u4p = new Vector3(u4.X - guai, u4.Y, u4.Z);

                    //Kp=fun.polar(K,0,r/tan((pi-kapr)/2)-r)
                    //i4=fun.polar(Kp,kapr-pi,r/tan(epsr/2)-r/tan((pi-kapr)/2))
                    Vector2 kp = fun.Polar(Vector2.Zero, 0, repsilon / Math.Tan((pi - cutagl) / 2) - repsilon);
                    Vector2 twoi4 = fun.Polar(kp, cutagl - pi, repsilon / Math.Tan(insertAngle / 2) - repsilon / Math.Tan((pi - cutagl) / 2));
                    Vector2[] twois = Pus.DiamondPoints(twoi4, l3, insertAngle, true, cutagl);
                    Vector2 twoi1 = twois[1];
                    Vector2 twoi2 = twois[2];
                    Vector2 twoi3 = twois[3];
                    double theoffset = Math.Tan(alphan) * s;
                    Vector2[] twoiis = Pus.OffsetPoints(theoffset, twois);
                    Vector2 twoii4 = twoiis[0];
                    Vector2 twoii3 = twoiis[3];
                    Vector2 twoii1 = twoiis[1];
                    Vector2 twoii2 = twoiis[2];

                    //刀头面
                    Vector3 i4 = new Vector3(twoi4.X, twoi4.Y, k.Z);
                    Vector3 i3 = new Vector3(twoi3.X, twoi3.Y, k.Z);
                    Vector3 i2 = new Vector3(twoi2.X, twoi2.Y, k.Z);
                    Vector3 i1 = new Vector3(twoi1.X, twoi1.Y, k.Z);
                    Vector2 cnm = Pus.IntersOnP(i1, new Vector3(i1.X + 1, i1.Y, i1.Z), u3p, u4p);
                    Vector3 dt1 = new Vector3(cnm.X, cnm.Y, u4.Z);
                    Vector3 dt2 = u3p;
                    Vector2 xx = Pus.IntersOnP(i3, i4, u2, u3);
                    Vector3 dt4 = Pus.KPoint(i3, new Vector3(xx.X, xx.Y, u3.Z), 0.7);
                    Vector3 dt3 = Pus.KPoint(u3, new Vector3(xx.X, xx.Y, u3.Z), 0.85);

                    Vector3 bdt1 = new Vector3(dt1.X, dt1.Y, b1.Z);
                    Vector3 b5 = new Vector3(twoii4.X, twoii4.Y, b1.Z);
                    Vector3 b4 = new Vector3(dt4.X, dt4.Y, b1.Z);
                    Vector3 b3 = new Vector3(dt3.X, dt3.Y, b1.Z);

                    Vector3 ii4 = new Vector3(twoii4.X, twoii4.Y, k.Z - s);
                    Vector3 ii3 = new Vector3(twoii3.X, twoii3.Y, k.Z - s);
                    Vector3 ii1 = new Vector3(twoii1.X, twoii1.Y, k.Z - s);
                    Vector3 ii2 = new Vector3(twoii2.X, twoii2.Y, k.Z - s);

                    i4 = Pus.LinearTrans(kscale, i4);
                    i3 = Pus.LinearTrans(kscale, i3);
                    i2 = Pus.LinearTrans(kscale, i2);
                    i1 = Pus.LinearTrans(kscale, i1);
                    dt1 = Pus.LinearTrans(kscale, dt1);
                    dt2 = Pus.LinearTrans(kscale, dt2);
                    dt3 = Pus.LinearTrans(kscale, dt3);
                    dt4 = Pus.LinearTrans(kscale, dt4);

                    ii4 = Pus.LinearTrans(kscale, ii4);
                    ii3 = Pus.LinearTrans(kscale, ii3);
                    ii2 = Pus.LinearTrans(kscale, ii2);
                    ii1 = Pus.LinearTrans(kscale, ii1);

                    b1 = Pus.LinearTrans(kscale, b1);
                    b2 = Pus.LinearTrans(kscale, b2);
                    b3 = Pus.LinearTrans(kscale, b3);
                    b4 = Pus.LinearTrans(kscale, b4);
                    b5 = Pus.LinearTrans(kscale, b5);
                    b6 = Pus.LinearTrans(kscale, b6);
                    bdt1 = Pus.LinearTrans(kscale, bdt1);

                    u1 = Pus.LinearTrans(kscale, u1);
                    u2 = Pus.LinearTrans(kscale, u2);
                    u3 = Pus.LinearTrans(kscale, u3);
                    u3p = Pus.LinearTrans(kscale, u3p);
                    u4 = Pus.LinearTrans(kscale, u4);


                    //主视图
                    LwPolyline mshank = Pus.AddPointsToLwPolyLine(u1, u2, u3, u4);
                    mshank.IsClosed = true;
                    fun.PolyFill(dxf, mshank, lineWidth, contour);

                    LwPolyline minsert = Pus.AddPointsToLwPolyLine(i4, i1, i2, i3);
                    minsert.IsClosed = true;
                    Pus.AglToArc(minsert, repsilon);

                    LwPolyline mhead = Pus.AddPointsToLwPolyLine(i3, i2, i1, dt1, dt2, dt3, dt4, i3);
                    mhead.IsClosed = true;
                    fun.PolyFill(dxf, mhead, lineWidth, contour);
                    LwPolyline mheadc1 = Pus.AddPointsToLwPolyLine(dt1, u4);
                    fun.PolyFill(dxf, mheadc1, lineWidth, contour);
                    LwPolyline mheadc2 = Pus.AddPointsToLwPolyLine(dt2, u3);
                    fun.PolyFill(dxf, mheadc2, lineWidth, contour);

                    fun.PolyFill(dxf, minsert, lineWidth, cutting);
                    //m视图标注
                    DimensionStyle dimensionStyle = new DimensionStyle("mystyle");
                    dimensionStyle.ArrowSize = kscale * 1.2;
                    dimensionStyle.DimArrow1 = DimensionArrowhead.Closedfilled;
                    dimensionStyle.DimArrow2 = DimensionArrowhead.Closedfilled;
                    dimensionStyle.TextHeight = kscale;
                    dimensionStyle.TextOffset = kscale / 2;
                    double offset = 7 * kscale;
                    LinearDimension dim_f = new LinearDimension(new Line(new Vector2(k.X, k.Y), new Vector2(b3.X, b3.Y)), offset * 1.5, Pus.Degree(b1, b2), dimensionStyle);
                    fun.dxflinedim(dxf, dim_f, f);
                    LinearDimension dim_l1 = new LinearDimension(new Line(new Vector2(k.X, k.Y), new Vector2(b1.X, b1.Y)), offset * 1.5, Pus.Degree(new Vector2(b1.X, b1.Y), new Vector2(b6.X, b6.Y)), dimensionStyle);
                    fun.dxflinedim(dxf, dim_l1, l1);
                    LinearDimension dim_l2 = new LinearDimension(new Line(new Vector2(k.X, k.Y), new Vector2(u4.X, u4.Y)), offset, Pus.Degree(new Vector2(u1.X, u1.Y), new Vector2(u4.X, u4.Y)), dimensionStyle);
                    fun.dxflinedim(dxf, dim_l2, l2);
                    //LinearDimension dim_l3 = new LinearDimension(new Line(i2, i3), offset, Pus.Degree(new Vector2(i3.X, i3.Y), new Vector2(i2.X, i2.Y)), dimensionStyle);
                    //fun.dxflinedim(dxf, dim_l3, Math.Round(l3, 2));
                    LinearDimension dim_b = new LinearDimension(new Line(new Vector2(u1.X, u1.Y), new Vector2(u2.X, u2.Y)), offset, Pus.Degree(new Vector2(u2.X, u2.Y), new Vector2(u1.X, u1.Y)), dimensionStyle);
                    fun.dxflinedim(dxf, dim_b, b);
                    //Angular2LineDimension dim_insertAgl = new Angular2LineDimension(new Line(i4, i3), new Line(i4, i1), offset * 0.5, dimensionStyle);
                    //dim_insertAgl.UserText = Math.Round(insertAngle * 180 / pi, 2) + "°";
                    //dxf.AddEntity(dim_insertAgl);
                    Angular2LineDimension dim_cutagl = new Angular2LineDimension(new Line(i4, i1), new Line(new Vector2(i4.X, i4.Y), fun.Polar(new Vector2(i4.X, i4.Y), -pi / 2, 1)), offset * 0.4, dimensionStyle);
                    dim_cutagl.UserText = Math.Round(cutagl * 180 / pi, 2) + "°";
                    dxf.AddEntity(dim_cutagl);
                    //RadialDimension dim_repsilon = new RadialDimension(Pus.GetArcFromPline(minsert, 1), Pus.Degree(i3, i4) - 10, offset * 0.5, dimensionStyle);
                    //dim_repsilon.UserText = "rε=" + repsilon;
                    //dxf.AddEntity(dim_repsilon);
                    //放倒(所有点)尚未平移到下方，因为只能绕着原点k所在轴旋转
                    Vector3 rotate = new Vector3(-1, 0, 0);
                    double rotateAgl = pi / 2;
                    i4 = Pus.Rodrigue(rotate, 1, rotateAgl, i4);
                    i3 = Pus.Rodrigue(rotate, 1, rotateAgl, i3);
                    i2 = Pus.Rodrigue(rotate, 1, rotateAgl, i2);
                    i1 = Pus.Rodrigue(rotate, 1, rotateAgl, i1);
                    dt1 = Pus.Rodrigue(rotate, 1, rotateAgl, dt1);
                    dt2 = Pus.Rodrigue(rotate, 1, rotateAgl, dt2);
                    dt3 = Pus.Rodrigue(rotate, 1, rotateAgl, dt3);
                    dt4 = Pus.Rodrigue(rotate, 1, rotateAgl, dt4);
                    ii4 = Pus.Rodrigue(rotate, 1, rotateAgl, ii4);
                    ii3 = Pus.Rodrigue(rotate, 1, rotateAgl, ii3);
                    ii2 = Pus.Rodrigue(rotate, 1, rotateAgl, ii2);
                    ii1 = Pus.Rodrigue(rotate, 1, rotateAgl, ii1);

                    b1 = Pus.Rodrigue(rotate, 1, rotateAgl, b1);
                    b2 = Pus.Rodrigue(rotate, 1, rotateAgl, b2);
                    b3 = Pus.Rodrigue(rotate, 1, rotateAgl, b3);
                    b4 = Pus.Rodrigue(rotate, 1, rotateAgl, b4);
                    b5 = Pus.Rodrigue(rotate, 1, rotateAgl, b5);
                    b6 = Pus.Rodrigue(rotate, 1, rotateAgl, b6);
                    bdt1 = Pus.Rodrigue(rotate, 1, rotateAgl, bdt1);

                    u1 = Pus.Rodrigue(rotate, 1, rotateAgl, u1);
                    u2 = Pus.Rodrigue(rotate, 1, rotateAgl, u2);
                    u3 = Pus.Rodrigue(rotate, 1, rotateAgl, u3);
                    u3p = Pus.Rodrigue(rotate, 1, rotateAgl, u3p);
                    u4 = Pus.Rodrigue(rotate, 1, rotateAgl, u4);

                    //创建lambds
                    rotate = new Vector3(Math.Sin(cutagl - pi / 2), k.Z, Math.Cos(cutagl - pi / 2));
                    rotateAgl = lambdas;
                    i4 = Pus.Rodrigue(rotate, 1, rotateAgl, i4);
                    i3 = Pus.Rodrigue(rotate, 1, rotateAgl, i3);
                    i2 = Pus.Rodrigue(rotate, 1, rotateAgl, i2);
                    i1 = Pus.Rodrigue(rotate, 1, rotateAgl, i1);
                    ii4 = Pus.Rodrigue(rotate, 1, rotateAgl, ii4);
                    ii3 = Pus.Rodrigue(rotate, 1, rotateAgl, ii3);
                    ii2 = Pus.Rodrigue(rotate, 1, rotateAgl, ii2);
                    ii1 = Pus.Rodrigue(rotate, 1, rotateAgl, ii1);
                    dt1 = Pus.Rodrigue(rotate, 1, rotateAgl, dt1);
                    dt2 = Pus.Rodrigue(rotate, 1, rotateAgl, dt2);
                    dt3 = Pus.Rodrigue(rotate, 1, rotateAgl, dt3);
                    dt4 = Pus.Rodrigue(rotate, 1, rotateAgl, dt4);

                    //创建gamo
                    double disi1_i4 = Vector3.Distance(i1, i4);
                    rotate = (i1 - i4) / disi1_i4;
                    rotateAgl = gamao;
                    i4 = Pus.Rodrigue(rotate, 1, rotateAgl, i4);
                    i3 = Pus.Rodrigue(rotate, 1, rotateAgl, i3);
                    i2 = Pus.Rodrigue(rotate, 1, rotateAgl, i2);
                    i1 = Pus.Rodrigue(rotate, 1, rotateAgl, i1);
                    ii4 = Pus.Rodrigue(rotate, 1, rotateAgl, ii4);
                    ii3 = Pus.Rodrigue(rotate, 1, rotateAgl, ii3);
                    ii2 = Pus.Rodrigue(rotate, 1, rotateAgl, ii2);
                    ii1 = Pus.Rodrigue(rotate, 1, rotateAgl, ii1);
                    dt1 = Pus.Rodrigue(rotate, 1, rotateAgl, dt1);
                    dt2 = Pus.Rodrigue(rotate, 1, rotateAgl, dt2);
                    dt3 = Pus.Rodrigue(rotate, 1, rotateAgl, dt3);
                    dt4 = Pus.Rodrigue(rotate, 1, rotateAgl, dt4);

                    //重新计算刀头的点
                    Face3d face4dt = new Face3d(dt2, dt3, dt4);
                    Vector3 v4dt = u2 - b2;
                    dt1 = Pus.Inters(face4dt, new Line(bdt1, bdt1 + v4dt));
                    dt2 = Pus.Inters(face4dt, new Line(u3p, u3p + v4dt));
                    dt3 = Pus.Inters(face4dt, new Line(b3, b3 + v4dt));
                    dt4 = Pus.Inters(face4dt, new Line(b4, b4 + v4dt));

                    Face3d face4buttom = new Face3d(b1, b2, b3);
                    b5 = Pus.Inters(face4buttom, new Line(ii4, ii4 + v4dt));
                    Vector3 bx = Pus.Inters(face4buttom, new Line(ii1, ii1 + v4dt));
                    bdt1 = Pus.Inters(face4buttom, new Line(dt1, dt1 + v4dt));

                    //平移所有点到下方
                    Vector3 voff = new Vector3(0, -b * kscale - offset * 1.5, 0);
                    Vector3 mk = Pus.OffsetXY(voff, k);
                    Vector3 mi4 = Pus.OffsetXY(voff, i4);
                    Vector3 mi3 = Pus.OffsetXY(voff, i3);
                    Vector3 mi2 = Pus.OffsetXY(voff, i2);
                    Vector3 mi1 = Pus.OffsetXY(voff, i1);
                    Vector3 mdt1 = Pus.OffsetXY(voff, dt1);
                    Vector3 mdt2 = Pus.OffsetXY(voff, dt2);
                    Vector3 mdt3 = Pus.OffsetXY(voff, dt3);
                    Vector3 mdt4 = Pus.OffsetXY(voff, dt4);
                    Vector3 mii4 = Pus.OffsetXY(voff, ii4);
                    Vector3 mii3 = Pus.OffsetXY(voff, ii3);
                    Vector3 mii2 = Pus.OffsetXY(voff, ii2);
                    Vector3 mii1 = Pus.OffsetXY(voff, ii1);

                    Vector3 mb1 = Pus.OffsetXY(voff, b1);
                    Vector3 mb2 = Pus.OffsetXY(voff, b2);
                    Vector3 mb3 = Pus.OffsetXY(voff, b3);
                    Vector3 mb4 = Pus.OffsetXY(voff, b4);
                    Vector3 mb5 = Pus.OffsetXY(voff, b5);
                    Vector3 mb6 = Pus.OffsetXY(voff, b6);
                    Vector3 mbx = Pus.OffsetXY(voff, bx);
                    Vector3 mbdt1 = Pus.OffsetXY(voff, bdt1);

                    Vector3 mu1 = Pus.OffsetXY(voff, u1);
                    Vector3 mu2 = Pus.OffsetXY(voff, u2);
                    Vector3 mu3 = Pus.OffsetXY(voff, u3);
                    Vector3 mu4 = Pus.OffsetXY(voff, u4);

                    LwPolyline lshank = Pus.AddPointsToLwPolyLine(mb1, mu1, mu4, mb6);
                    lshank.IsClosed = true;
                    fun.PolyFill(dxf, lshank, lineWidth, contour);
                    LwPolyline lshank_dt = Pus.AddPointsToLwPolyLine(mdt1, mu4);
                    fun.PolyFill(dxf, lshank_dt, lineWidth, contour);
                    LwPolyline lshank_dt1 = Pus.AddPointsToLwPolyLine(mdt2, mu3);
                    fun.PolyFill(dxf, lshank_dt1, lineWidth, contour);

                    LwPolyline lhead = Pus.AddPointsToLwPolyLine(mii4, mb5, mbdt1, mdt1);
                    fun.PolyFill(dxf, lhead, lineWidth, contour);
                    LwPolyline lhead1 = Pus.AddPointsToLwPolyLine(mbdt1, mb6);
                    fun.PolyFill(dxf, lhead1, lineWidth, contour);
                    LwPolyline lhead2 = Pus.AddPointsToLwPolyLine(mdt1, mi1);
                    fun.PolyFill(dxf, lhead2, lineWidth, contour);
                    LwPolyline lhead3 = Pus.AddPointsToLwPolyLine(mdt1, mbdt1);
                    fun.PolyFill(dxf, lhead3, lineWidth, contour);
                    LwPolyline lhead4 = Pus.AddPointsToLwPolyLine(mbx, mii1);
                    fun.PolyFill(dxf, lhead4, lineWidth, contour);
                    if (gamao > 0)
                    {
                        LwPolyline lheadu = Pus.AddPointsToLwPolyLine(mi1, mdt1, mdt2, mdt3, mdt4, mi3);
                        fun.PolyFill(dxf, lheadu, lineWidth, contour);

                        LwPolyline linsertu = Pus.AddPointsToLwPolyLine(mi4, mi1, mi2, mi3);
                        linsertu.IsClosed = true;
                        fun.PolyFill(dxf, linsertu, lineWidth, cutting);
                    }

                    LwPolyline linsertf = Pus.AddPointsToLwPolyLine(mi4, mii4, mii1, mi1);
                    linsertf.IsClosed = true;
                    fun.PolyFill(dxf, linsertf, lineWidth, cutting);
                    //l视图标注
                    LinearDimension dim_h1 = new LinearDimension(new Line(new Vector2(mk.X, mk.Y), new Vector2(mb5.X, mb5.Y)), offset * 0.5, Pus.Degree(b1, u1), dimensionStyle);
                    fun.dxflinedim(dxf, dim_h1, h1);
                    LinearDimension dim_h2 = new LinearDimension(new Line(new Vector2(mu1.X, mu1.Y), new Vector2(mb1.X, mb1.Y)), offset, Pus.Degree(u1, b1), dimensionStyle);
                    fun.dxflinedim(dxf, dim_h2, h2);
                    if (lambdas == 0)
                        Pus.NeedleDim(dxf, new Line(new Vector2(mi4.X, mi4.Y), fun.Polar(new Vector2(mi4.X, mi4.Y), pi / 180, 1)), new Line(mi4, mi4 + mu4 - mu2), kscale * offset, "λs=0°", dimensionStyle);
                    else
                        Pus.NeedleDim(dxf, new Line(mi4, mi1), new Line(mi4, mi4 + mu4 - mu2), kscale * offset, "λs=" + Math.Round(lambdas * 180 / pi, 2) + "°", dimensionStyle);
                    //左视图
                    //所有点移动到原点
                    //立正
                    rotate = new Vector3(1, 0, 0);
                    rotateAgl = pi / 2;
                    Vector3 zi4 = Pus.Rodrigue(rotate, 1, rotateAgl, i4);
                    Vector3 zi3 = Pus.Rodrigue(rotate, 1, rotateAgl, i3);
                    Vector3 zi2 = Pus.Rodrigue(rotate, 1, rotateAgl, i2);
                    Vector3 zi1 = Pus.Rodrigue(rotate, 1, rotateAgl, i1);
                    Vector3 zdt1 = Pus.Rodrigue(rotate, 1, rotateAgl, dt1);
                    Vector3 zdt2 = Pus.Rodrigue(rotate, 1, rotateAgl, dt2);
                    Vector3 zdt3 = Pus.Rodrigue(rotate, 1, rotateAgl, dt3);
                    Vector3 zdt4 = Pus.Rodrigue(rotate, 1, rotateAgl, dt4);

                    Vector3 zii4 = Pus.Rodrigue(rotate, 1, rotateAgl, ii4);
                    Vector3 zii3 = Pus.Rodrigue(rotate, 1, rotateAgl, ii3);
                    Vector3 zii2 = Pus.Rodrigue(rotate, 1, rotateAgl, ii2);
                    Vector3 zii1 = Pus.Rodrigue(rotate, 1, rotateAgl, ii1);

                    Vector3 zb1 = Pus.Rodrigue(rotate, 1, rotateAgl, b1);
                    Vector3 zb2 = Pus.Rodrigue(rotate, 1, rotateAgl, b2);
                    Vector3 zb3 = Pus.Rodrigue(rotate, 1, rotateAgl, b3);
                    Vector3 zb4 = Pus.Rodrigue(rotate, 1, rotateAgl, b4);
                    Vector3 zb5 = Pus.Rodrigue(rotate, 1, rotateAgl, b5);
                    Vector3 zb6 = Pus.Rodrigue(rotate, 1, rotateAgl, b6);
                    Vector3 zbx = Pus.Rodrigue(rotate, 1, rotateAgl, bx);
                    Vector3 zbdt1 = Pus.Rodrigue(rotate, 1, rotateAgl, bdt1);

                    Vector3 zu1 = Pus.Rodrigue(rotate, 1, rotateAgl, u1);
                    Vector3 zu2 = Pus.Rodrigue(rotate, 1, rotateAgl, u2);
                    Vector3 zu3 = Pus.Rodrigue(rotate, 1, rotateAgl, u3);
                    Vector3 zu4 = Pus.Rodrigue(rotate, 1, rotateAgl, u4);

                    //绕y转，露出左面
                    rotate = new Vector3(0, 1, 0);
                    rotateAgl = pi / 2;
                    zi4 = Pus.Rodrigue(rotate, 1, rotateAgl, zi4);
                    zi3 = Pus.Rodrigue(rotate, 1, rotateAgl, zi3);
                    zi2 = Pus.Rodrigue(rotate, 1, rotateAgl, zi2);
                    zi1 = Pus.Rodrigue(rotate, 1, rotateAgl, zi1);
                    zdt1 = Pus.Rodrigue(rotate, 1, rotateAgl, zdt1);
                    zdt2 = Pus.Rodrigue(rotate, 1, rotateAgl, zdt2);
                    zdt3 = Pus.Rodrigue(rotate, 1, rotateAgl, zdt3);
                    zdt4 = Pus.Rodrigue(rotate, 1, rotateAgl, zdt4);

                    zii4 = Pus.Rodrigue(rotate, 1, rotateAgl, zii4);
                    zii3 = Pus.Rodrigue(rotate, 1, rotateAgl, zii3);
                    zii2 = Pus.Rodrigue(rotate, 1, rotateAgl, zii2);
                    zii1 = Pus.Rodrigue(rotate, 1, rotateAgl, zii1);

                    zb1 = Pus.Rodrigue(rotate, 1, rotateAgl, zb1);
                    zb2 = Pus.Rodrigue(rotate, 1, rotateAgl, zb2);
                    zb3 = Pus.Rodrigue(rotate, 1, rotateAgl, zb3);
                    zb4 = Pus.Rodrigue(rotate, 1, rotateAgl, zb4);
                    zb5 = Pus.Rodrigue(rotate, 1, rotateAgl, zb5);
                    zb6 = Pus.Rodrigue(rotate, 1, rotateAgl, zb6);
                    zbx = Pus.Rodrigue(rotate, 1, rotateAgl, zbx);
                    zbdt1 = Pus.Rodrigue(rotate, 1, rotateAgl, zbdt1);

                    zu1 = Pus.Rodrigue(rotate, 1, rotateAgl, zu1);
                    zu2 = Pus.Rodrigue(rotate, 1, rotateAgl, zu2);
                    zu3 = Pus.Rodrigue(rotate, 1, rotateAgl, zu3);
                    zu4 = Pus.Rodrigue(rotate, 1, rotateAgl, zu4);

                    //平移
                    voff = new Vector3(-b * kscale - offset * 2, 0, 0);
                    zi4 = Pus.OffsetXY(voff, zi4);
                    zi3 = Pus.OffsetXY(voff, zi3);
                    zi2 = Pus.OffsetXY(voff, zi2);
                    zi1 = Pus.OffsetXY(voff, zi1);
                    zdt1 = Pus.OffsetXY(voff, zdt1);
                    zdt2 = Pus.OffsetXY(voff, zdt2);
                    zdt3 = Pus.OffsetXY(voff, zdt3);
                    zdt4 = Pus.OffsetXY(voff, zdt4);

                    zii4 = Pus.OffsetXY(voff, zii4);
                    zii3 = Pus.OffsetXY(voff, zii3);
                    zii2 = Pus.OffsetXY(voff, zii2);
                    zii1 = Pus.OffsetXY(voff, zii1);

                    zb1 = Pus.OffsetXY(voff, zb1);
                    zb2 = Pus.OffsetXY(voff, zb2);
                    zb3 = Pus.OffsetXY(voff, zb3);
                    zb4 = Pus.OffsetXY(voff, zb4);
                    zb5 = Pus.OffsetXY(voff, zb5);
                    zb6 = Pus.OffsetXY(voff, zb6);
                    zbx = Pus.OffsetXY(voff, zbx);
                    zbdt1 = Pus.OffsetXY(voff, zbdt1);

                    zu1 = Pus.OffsetXY(voff, zu1);
                    zu2 = Pus.OffsetXY(voff, zu2);
                    zu3 = Pus.OffsetXY(voff, zu3);
                    zu4 = Pus.OffsetXY(voff, zu4);

                    //左视图绘制
                    LwPolyline zshank = Pus.AddPointsToLwPolyLine(zii4, zb5, zb4, zb3, zdt3, zdt4, zi3);
                    fun.PolyFill(dxf, zshank, lineWidth, contour);
                    LwPolyline zshank2 = Pus.AddPointsToLwPolyLine(zb4, zdt4);
                    fun.PolyFill(dxf, zshank2, lineWidth, contour);
                    if (lambdas > 0)
                    {
                        LwPolyline zshank1 = Pus.AddPointsToLwPolyLine(zdt3, zdt2, zdt1, zi1);
                        fun.PolyFill(dxf, zshank1, lineWidth, contour);

                        LwPolyline zinsert = Pus.AddPointsToLwPolyLine(zi4, zi1, zi2, zi3);
                        zinsert.IsClosed = true;
                        fun.PolyFill(dxf, zinsert, lineWidth, cutting);
                    }

                    LwPolyline zlen1 = Pus.AddPointsToLwPolyLine(zi3, zii3, zii4, zi4);
                    zlen1.IsClosed = true;
                    fun.PolyFill(dxf, zlen1, lineWidth, cutting);

                    if (cutagl < pi / 2)
                    {
                        LwPolyline zlen2 = Pus.AddPointsToLwPolyLine(zii4, zii1, zi1, zi4);
                        fun.PolyFill(dxf, zlen2, lineWidth, cutting);
                    }
                    //if (zdt1.Y > zu4.Y)
                    //{
                    //    Vector2 visible = Pus.IntersOnP(zi4, zi1, zb4, zu4);
                    //    LwPolyline visiLine = Pus.AddPointsToLwPolyLine(zdt1, zu4);
                    //    Pus.AddPointsToLwPolyLine(visiLine, visible);
                    //    fun.PolyFill(dxf, visiLine, lineWidth, contour);
                    //}
                    //左视图标注
                    //刃倾角
                    if (gamao == 0)
                        Pus.NeedleDim(dxf, new Line(new Vector2(zi4.X, zi4.Y), fun.Polar(new Vector2(zi4.X, zi4.Y), Pus.AngleOnP(zi3, zi4) + pi / 180, 1)), new Line(zi3, zi4), offset * 1.5, "γo=0°", dimensionStyle);
                    else
                        Pus.NeedleDim(dxf, new Line(zi3, zi4), new Line(new Vector2(zi4.X, zi4.Y), fun.Polar(new Vector2(zi4.X, zi4.Y), Pus.AngleOnP(zi3, zi4) + gamao, 1)), offset * 1.5, "γo=" + Math.Round(lambdas * 180 / pi, 2) + "°", dimensionStyle);

                    //LinearDimension dim_s = new LinearDimension(new Line(zi4, zii4), offset, Pus.Degree(zi4, zi3) + 90, dimensionStyle);
                    //fun.dxflinedim(dxf, dim_s, s);

                    //后角
                    if (alphan == 0)
                        Pus.NeedleDim(dxf, new Line(zi4, zii4), new Line(new Vector2(zi4.X, zi4.Y), fun.Polar(new Vector2(zi4.X, zi4.Y), Pus.AngleOnP(zi4, zii4) + pi / 180, 1)), offset + h1 * kscale, "αn=0°", dimensionStyle);
                    else
                        Pus.NeedleDim(dxf, new Line(zi4, zii4), new Line(new Vector2(zi4.X, zi4.Y), fun.Polar(new Vector2(zi4.X, zi4.Y), Pus.AngleOnP(zi4, zii4) + alphan, 1)), offset + h1 * kscale, "αn=" + Math.Round(alphan * 180 / pi, 2) + "°", dimensionStyle);
                    //图框
                    if (Convert.ToDouble(data["isframe"]) == 1)
                    {
                        Vector2 c4c = new Vector2((b2.X + zb3.X) / 2, (b2.Y + mu1.Y) / 2);
                        Dictionary<string, Vector2> positions = Frame.frameA3X(dxf, new Vector2(c4c.X - 420 / 2, c4c.Y + 297 / 2), new Dictionary<string, object>());
                        fun.writetextofC(dxf, kscale + ":1", positions["比例"], 3.5, 0, 0.6, 3);
                    }

                    dxf.DrawingVariables.AcadVer = DxfVersion.AutoCad2007;
                    dxf.Save(path);
                }
        */
        public static void StyleG_InsertC(Dictionary<string, Object> data)
        {
            DxfDocument dxf = new DxfDocument();
            dxf.Layers["0"].Lineweight = Lineweight.W25;
            Layer contour = new Layer("contour");//轮廓层
            Layer dimensioning = new Layer("dimensioning");//尺寸层
            Layer refin = new Layer("refin");//基准线/内轮廓/虚线
            Layer center = new Layer("center");//中心线
            Layer textlayer = new Layer("textlayer");//文本层
            Layer hatching = new Layer("hatching");//填充层
            Layer additionalline = new Layer("additionalline");//附加线
            Layer cutting = new Layer("cutting");//切削层
            fun.SetLayer(dxf);

            //基本参数-------------------------------------------------------------------------------------------------
            double pi = Math.PI;
            string path = Convert.ToString(data["path"]);

            //参数名称取自ISO 5610-4
            //赋值参数--------------------------------------------------------------------------------------------------
            double b = 31.77;
            double l1 = 163.17;
            double l2 = 38.76;
            double f = 38.41;
            double l3 = 19.96;
            double h2 = 32.62;
            double h1 = 32.01;
            double s = 7.36;

            //点---------------------------------------------------------------------------------------------
            //第一部分
            //方形
            //轮廓
            Vector2 v1 = new Vector2(0.0);
            Vector2 v2 = new Vector2(v1.X + 0.4468 * f, v1.Y + 0.15317 * l3);
            Vector2 v3 = new Vector2(v2.X, v2.Y - 0.1042 * l3);
            Vector2 v4 = new Vector2(v3.X + 0.5334 * f, v3.Y + 0.1808 * l3);
            Vector2 v5 = new Vector2(v4.X, v4.Y + 1.043 * l3);
            Vector2 v6 = new Vector2(v5.X - 0.02499 * f, v5.Y + 0.009 * l3);
            Vector2 v7 = new Vector2(v2.X, v5.Y + 0.1803 * l3);
            Vector2 v8 = new Vector2(v6.X, v6.Y + 0.9013 * l3);
            Vector2 v9 = new Vector2(v8.X - 0.1081 * f, v8.Y);
            Vector2 v10 = new Vector2(v9.X - b, v9.Y);
            Vector2 v11 = new Vector2(v9.X, v9.Y + 0.4365 * l1);
            Vector2 v12 = new Vector2(v11.X, v11.Y + h2);
            Vector2 v13 = new Vector2(v12.X, v12.Y + 0.5938 * h2);
            Vector2 v14 = new Vector2(v13.X - b, v13.Y);
            Vector2 v15 = new Vector2(v12.X - b, v12.Y);
            Vector2 v16 = new Vector2(v11.X - b, v11.Y);
            Vector2 v17 = new Vector2(v1.X - 2.342 * f, v1.Y - 0.4033 * l3);
            Vector2 v18 = new Vector2(v17.X + 0.6941 * f, v17.Y);
            Vector2 v19 = new Vector2(v18.X + 0.1023 * f, v18.Y + h1);
            Vector2 v20 = new Vector2(v19.X - 0.8456 * f, v19.Y);
            Vector2 v21 = new Vector2(v20.X + 0.30278 * f, v20.Y);
            Vector2 v22 = new Vector2(v21.X + 0.0421 * f, v21.Y - 0.23177 * h1);
            Vector2 v23 = new Vector2(v22.X + 0.4769 * f, v22.Y);
            Vector2 v24 = new Vector2(v20.X + 0.2904 * f, v20.Y + 1.4992 * h1);
            Vector2 v25 = new Vector2(v24.X + s, v24.Y + 0.0288 * h2);
            Vector2 v26 = new Vector2(v24.X + 0.537 * f, v24.Y + 0.0809 * h2);
            Vector2 v27 = new Vector2(v25.X, v25.Y + 0.5898 * h2);
            Vector2 v28 = new Vector2(v24.X, v24.Y + 0.648 * h2);
            Vector2 v29 = new Vector2(v24.X, v24.Y + 1.4816 * h2);


            //作图部分-----------------------------------------------------------------------
            //第一部分
            //轮廓
            LwPolyline polyline1 = new LwPolyline();
            polyline1.Vertexes.Add(new LwPolylineVertex(v1));
            polyline1.Vertexes.Add(new LwPolylineVertex(v2));
            polyline1.Vertexes.Add(new LwPolylineVertex(v3));
            polyline1.Vertexes.Add(new LwPolylineVertex(v4));
            polyline1.Vertexes.Add(new LwPolylineVertex(v5));
            polyline1.Vertexes.Add(new LwPolylineVertex(v7));
            polyline1.Vertexes.Add(new LwPolylineVertex(v3));
            fun.PolyFill(dxf, polyline1, 0.1, contour);
            ////倒角
            //var arc1 = Pus.Fillet4LwPline(polyline1, 2, RE);
            //var arc2 = Pus.Fillet4LwPline(arc1, 4, RE);
            //var arc3 = Pus.Fillet4LwPline(arc2, 6, RE);
            //var arc4 = Pus.Fillet4LwPline(arc3, 7, RE);
            //fun.PolyFill(dxf, arc4, 0.3, contour);

            LwPolyline polyline2 = new LwPolyline();
            polyline2.Vertexes.Add(new LwPolylineVertex(v9));
            polyline2.Vertexes.Add(new LwPolylineVertex(v11));
            polyline2.Vertexes.Add(new LwPolylineVertex(v12));
            polyline2.Vertexes.Add(new LwPolylineVertex(v15));
            polyline2.Vertexes.Add(new LwPolylineVertex(v14));
            polyline2.Vertexes.Add(new LwPolylineVertex(v13));
            polyline2.Vertexes.Add(new LwPolylineVertex(v11));
            polyline2.Vertexes.Add(new LwPolylineVertex(v16));
            polyline2.Vertexes.Add(new LwPolylineVertex(v15));
            polyline2.Vertexes.Add(new LwPolylineVertex(v10));
            polyline2.Vertexes.Add(new LwPolylineVertex(v1));
            fun.PolyFill(dxf, polyline2, 0.1, contour);


            LwPolyline polyline3 = new LwPolyline();
            polyline3.Vertexes.Add(new LwPolylineVertex(v17));
            polyline3.Vertexes.Add(new LwPolylineVertex(v18));
            polyline3.Vertexes.Add(new LwPolylineVertex(v19));
            polyline3.Vertexes.Add(new LwPolylineVertex(v20));
            polyline3.Vertexes.Add(new LwPolylineVertex(v21));
            polyline3.Vertexes.Add(new LwPolylineVertex(v22));
            polyline3.Vertexes.Add(new LwPolylineVertex(v23));
            fun.PolyFill(dxf, polyline3, 0.1, contour);

            LwPolyline polyline4 = new LwPolyline();
            polyline4.Vertexes.Add(new LwPolylineVertex(v26));
            polyline4.Vertexes.Add(new LwPolylineVertex(v25));
            polyline4.Vertexes.Add(new LwPolylineVertex(v27));
            polyline4.Vertexes.Add(new LwPolylineVertex(v28));
            polyline4.Vertexes.Add(new LwPolylineVertex(v29));
            polyline4.Vertexes.Add(new LwPolylineVertex(v24));
            polyline4.Vertexes.Add(new LwPolylineVertex(v25));
            fun.PolyFill(dxf, polyline4, 0.1, contour);



            //图框
            /*            if (Convert.ToDouble(data["isframe"]) == 1)
                        {
                            Vector2 c4c = new Vector2((b2.X + zb3.X) / 2, (b2.Y + mu1.Y) / 2);
                            Dictionary<string, Vector2> positions = Frame.frameA3X(dxf, new Vector2(c4c.X - 420 / 2, c4c.Y + 297 / 2), new Dictionary<string, object>());
                            fun.writetextofC(dxf, kscale + ":1", positions["比例"], 3.5, 0, 0.6, 3);
                        }
            */
            fun.SetLayer(dxf);
            fun.SetByLayer(dxf);

            dxf.DrawingVariables.AcadVer = DxfVersion.AutoCad2007;
            dxf.Save(path);
        }

        public static void StyleG_InsertT(Dictionary<string, Object> data)
        {
            DxfDocument dxf = new DxfDocument();
            Layer contour = new Layer("contour") { Color = AciColor.Cyan };    //1,轮廓层
            Layer cutting = new Layer("cutting") { Color = AciColor.Red };    //切削层
            cutting.Lineweight = Lineweight.W200;

            string path = Convert.ToString(data["path"]);
            //参数名称取自ISO 5610-4
            double b = 12;
            double l1 = 100;
            double l2 = 25;
            double f = 16;
            double l3 = 11;
            double h2 = 12;
            double h1 = 12;
            double s = 2.38;
            double insertAngle = 60 * pi / 180;
            double alphan = 11 * pi / 180;
            double cutagl = 90 * pi / 180;
            double lambdas = 0;
            double gammao = 0;
            double repsilon = 0;
            #region
            try
            {
                if (data["re"] != null)
                    repsilon = Convert.ToDouble(data["re"]);
                if (repsilon <= 0)
                    repsilon = 0.01;
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["lams"] != null)
                    lambdas = Convert.ToDouble(data["lams"]) * pi / 180;
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["gamo"] != null)
                    gammao = Convert.ToDouble(data["gamo"]) * pi / 180;
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["b"] != null)
                    b = Convert.ToDouble(data["b"]);
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["s"] != null)
                    s = Convert.ToDouble(data["s"]);
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["lf"] != null)
                    l1 = Convert.ToDouble(data["lf"]);
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["lh"] != null)
                    l2 = Convert.ToDouble(data["lh"]);
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["wf"] != null)
                    f = Convert.ToDouble(data["wf"]);
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["h"] != null)
                    h2 = Convert.ToDouble(data["h"]);
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["hf"] != null)
                    h1 = Convert.ToDouble(data["hf"]);
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["epsr"] != null)
                    insertAngle = Convert.ToDouble(data["epsr"]) * pi / 180;
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["kapr"] != null)
                    cutagl = Convert.ToDouble(data["kapr"]) * pi / 180;
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["an"] != null)
                    alphan = Convert.ToDouble(data["an"]) * pi / 180;
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["ic"] != null)
                    l3 = Pus.GetLByTIC(Convert.ToDouble(data["ic"]));
            }
            catch (KeyNotFoundException) { }
            #endregion
            double kscale = 1;
            if (l1 >= 120)
                kscale = 1;
            else
                kscale = 1.5;
            double lineWidth = 1;
            //k点位置恒定
            Vector3 k = new Vector3(0, 0, 0);
            RectShank rs = new RectShank(b, l1, f, l2, l3, 3, true, insertAngle, cutagl, lambdas, true, gammao, alphan, s, repsilon);
            Vector3[] shank = rs.Shank;
            Vector3[] inserts = rs.Inserts;
            //线性变换
            double theta = 0 * pi / 180;
            Matrix3 linearTrans = new Matrix3(
                Math.Cos(theta) * kscale, -Math.Sin(theta) * kscale, 0,
                Math.Sin(theta) * kscale, Math.Cos(theta) * kscale, 0,
                              0, 0, kscale
            );
            for (int i = 0; i < shank.Length; i++)
            {
                shank[i] = linearTrans * shank[i];
            }
            for (int i = 0; i < inserts.Length; i++)
            {
                inserts[i] = linearTrans * inserts[i];
            }
            repsilon *= kscale;

            Vector3[] head = new Vector3[13];
            Face3d fb = new Face3d(shank[0], shank[1], shank[2]);
            Face3d fbk = new Face3d(shank[1], shank[2], shank[6]);
            Face3d fiu = new Face3d(inserts[3], inserts[4], inserts[5]);
            Vector3 nbu = Pus.UnitVector(shank[0], shank[4]);
            head[0] = Pus.Inters(fb, inserts[0], inserts[0] + nbu);
            Face3d fd0 = new Face3d(inserts[0], inserts[1], head[0]);
            Vector3 fd1Mkr = Pus.ReferenceV3(head[0], 1, 1 / Math.Tan(10 * pi / 180), 0);
            Face3d fd1 = new Face3d(inserts[0], head[0], fd1Mkr);
            Face3d fc0 = new Face3d(Pus.ReferenceV3(shank[3], -kscale, 0, 0), Pus.ReferenceV3(shank[2], -kscale, 0, 0), Pus.ReferenceV3(shank[6], -kscale, 0, 0));
            Face3d fc1 = new Face3d(Pus.ReferenceV3(shank[3], -1.5 * kscale, 0, 0), Pus.ReferenceV3(shank[2], -1.5 * kscale, 0, 0), Pus.ReferenceV3(shank[6], -1.5 * kscale, 0, 0));
            head[1] = Pus.Inters(fc1, Pus.Inters(fd0, fb, head[0]));
            head[2] = Pus.Inters(fbk, Pus.Inters(fd1, fb, head[0]));
            head[3] = Pus.Inters(fd0, inserts[4], inserts[5]);
            head[4] = Pus.Inters(fc1, Pus.Inters(fiu, fd0, head[3]));
            Face3d fcq = new Face3d(shank[3], shank[7], head[4]);
            head[5] = Pus.Inters(fc0, Pus.Inters(fiu, fcq, head[4]));
            head[6] = Pus.Inters(fbk, Pus.Inters(fiu, fc0, head[5]));
            head[7] = Pus.Inters(fd1, Pus.Inters(fbk, fiu, head[6]));
            head[8] = Pus.Inters(fd1, inserts[3], inserts[5]);
            head[10] = Pus.KPoint(head[8], head[7], 0.7);
            head[11] = Pus.KPoint(head[0], head[2], 0.7);
            head[9] = Pus.KPoint(head[7], head[6], 0.2);
            Face3d fec = new Face3d(head[9], head[10], head[11]);
            head[12] = Pus.Inters(fec, shank[1], shank[2]);

            //mview
            LwPolyline msk = Pus.AddPointsToLwPolyLine(shank[4], shank[5], shank[6], shank[7]);
            msk.IsClosed = true;
            fun.PolyFill(dxf, msk, lineWidth, contour);

            LwPolyline mfiu = Pus.AddPointsToLwPolyLine(inserts[5], head[3], head[4], head[5], head[6], head[9], head[10], head[8]);
            mfiu.IsClosed = true;
            fun.PolyFill(dxf, mfiu, lineWidth, contour);
            LwPolyline mfcu = Pus.AddPointsToLwPolyLine(shank[7], shank[6], head[6], head[5]);
            mfcu.IsClosed = true;
            fun.PolyFill(dxf, mfcu, lineWidth, contour);

            LwPolyline mist = Pus.AddPointsToLwPolyLine(inserts[3], inserts[4], inserts[5]);
            mist.IsClosed = true;
            Pus.AglToArc(mist, repsilon);
            fun.PolyFill(dxf, mist, lineWidth, cutting);
            //mview标注
            DimensionStyle dimensionStyle = new DimensionStyle("mystyle");
            dimensionStyle.ArrowSize = kscale * 1.5;
            dimensionStyle.DimArrow1 = DimensionArrowhead.Closedfilled;
            dimensionStyle.DimArrow2 = DimensionArrowhead.Closedfilled;
            dimensionStyle.TextHeight = kscale * 1.5;
            dimensionStyle.TextOffset = kscale;
            double offset = 7 * kscale;
            LinearDimension dim_b = new LinearDimension(new Line(shank[5], shank[4]), offset, Pus.Degree(shank[5], shank[4]), dimensionStyle);
            fun.dxflinedim(dxf, dim_b, b);
            LinearDimension dim_f = new LinearDimension(new Line(Vector3.Zero, head[9]), head[9].X / 2 + offset, Pus.Degree(shank[4], shank[5]), dimensionStyle);
            fun.dxflinedim(dxf, dim_f, f);
            LinearDimension dim_l1 = new LinearDimension(new Line(Vector3.Zero, shank[4]), b / 2 * kscale, 180, dimensionStyle);
            fun.dxflinedim(dxf, dim_l1, l1);
            LinearDimension dim_l2 = new LinearDimension(new Line(shank[6], Vector3.Zero), shank[6].Y / 2 + offset, 0, dimensionStyle);
            fun.dxflinedim(dxf, dim_l2, l2);
            Angular2LineDimension dim_cutagl = new Angular2LineDimension(new Line(inserts[3], inserts[4]),
                new Line(Pus.ToV2(inserts[3]), fun.Polar(Pus.ToV2(inserts[3]), -pi / 2, 1)), offset, dimensionStyle);
            dim_cutagl.UserText = Math.Round(cutagl * 180 / pi, 1) + "°";
            dxf.AddEntity(dim_cutagl);

            //zview
            //绕y轴旋转pi/2再平移得到左视图
            Vector3[] zshank = new Vector3[shank.Length];
            Vector3[] zhead = new Vector3[head.Length];
            Vector3[] zinserts = new Vector3[inserts.Length];
            Vector3 zviewMkr = new Vector3(0, 1, 0);
            double yR = pi / 2;
            double zoffset = -2 * b * kscale;
            for (int i = 0; i < shank.Length; i++)
            {
                zshank[i] = Pus.Rodrigue(zviewMkr, 1, yR, shank[i]);
                zshank[i].X += zoffset;
            }
            for (int i = 0; i < inserts.Length; i++)
            {
                zinserts[i] = Pus.Rodrigue(zviewMkr, 1, yR, inserts[i]);
                zinserts[i].X += zoffset;
            }
            for (int i = 0; i < head.Length; i++)
            {
                zhead[i] = Pus.Rodrigue(zviewMkr, 1, yR, head[i]);
                zhead[i].X += zoffset;
            }
            Vector3 zk = k;
            zk.X += zoffset;

            LwPolyline zfd1 = Pus.AddPointsToLwPolyLine(zinserts[0], zhead[0], zhead[11], zhead[10], zhead[8]);
            zfd1.IsClosed = true;
            fun.PolyFill(dxf, zfd1, lineWidth, contour);
            LwPolyline zfec = Pus.AddPointsToLwPolyLine(zhead[9], zhead[10], zhead[11], zhead[12]);
            zfec.IsClosed = true;
            fun.PolyFill(dxf, zfec, lineWidth, contour);

            LwPolyline zist = Pus.AddPointsToLwPolyLine(zinserts[0], zinserts[3], zhead[8]);
            fun.PolyFill(dxf, zist, lineWidth, cutting);

            if (zinserts[4].X > zinserts[3].X)
            {
                LwPolyline zfiu = Pus.AddPointsToLwPolyLine(zinserts[5], zhead[3], zhead[4], zhead[5], zhead[6], zhead[9], zhead[10], zhead[8]);
                zfiu.IsClosed = true;
                fun.PolyFill(dxf, zfiu, lineWidth, contour);

                LwPolyline zistu = Pus.AddPointsToLwPolyLine(zinserts[3], zinserts[4], zinserts[5]);
                zistu.IsClosed = true;
                fun.PolyFill(dxf, zistu, lineWidth, cutting);
            }
            //zview标注
            LinearDimension dim_h1 = new LinearDimension(new Line(zk, zhead[0]), offset, Pus.Degree(zshank[4], zshank[0]), dimensionStyle);
            fun.dxflinedim(dxf, dim_h1, h1);

            Vector2 z3 = Pus.ToV2(zinserts[3]);
            if (gammao == 0)
            {
                gammao = 0.1 * pi / 180;
                Pus.NeedleDim(dxf, new Line(z3, fun.Polar(z3, -pi / 2, 1)),
                    new Line(z3, fun.Polar(z3, -pi / 2 + gammao, 1)), offset * 1.7, "γo=0°", dimensionStyle);
            }
            else
            {
                Pus.NeedleDim(dxf, new Line(z3, fun.Polar(z3, -pi / 2, 1)),
                    new Line(z3, fun.Polar(z3, -pi / 2 + gammao, 1)), offset * 1.7, "γo=" + Math.Round(gammao * 180 / pi, 2) + "°", dimensionStyle);
            }

            //lview
            Vector3[] lshank = new Vector3[shank.Length];
            Vector3[] linserts = new Vector3[inserts.Length];
            Vector3[] lhead = new Vector3[head.Length];
            //放倒
            Vector3 laydown = new Vector3(-1, 0, 0);
            double laydownR = pi / 2;
            double loffset = -h2 * 2 * kscale;
            for (int i = 0; i < shank.Length; i++)
            {
                lshank[i] = Pus.Rodrigue(laydown, 1, laydownR, shank[i]);
                lshank[i].Y += loffset;
            }

            for (int i = 0; i < inserts.Length; i++)
            {
                linserts[i] = Pus.Rodrigue(laydown, 1, laydownR, inserts[i]);
                linserts[i].Y += loffset;
            }

            for (int i = 0; i < head.Length; i++)
            {
                lhead[i] = Pus.Rodrigue(laydown, 1, laydownR, head[i]);
                lhead[i].Y += loffset;
            }
            Vector3 lk = k;
            lk.Y += loffset;

            LwPolyline lsk = Pus.AddPointsToLwPolyLine(lshank[0], lshank[4], lshank[7], lshank[3]);
            lsk.IsClosed = true;
            fun.PolyFill(dxf, lsk, lineWidth, contour);

            LwPolyline lfcq = Pus.AddPointsToLwPolyLine(lhead[1], lhead[4], lhead[5], lshank[7], lshank[3]);
            lfcq.IsClosed = true;
            fun.PolyFill(dxf, lfcq, lineWidth, contour);

            LwPolyline lfd0 = Pus.AddPointsToLwPolyLine(linserts[0], lhead[0], lhead[1], lhead[4], lhead[3]);
            fun.PolyFill(dxf, lfd0, lineWidth, contour);

            LwPolyline list0 = Pus.AddPointsToLwPolyLine(linserts[0], linserts[1], linserts[4], linserts[3]);
            list0.IsClosed = true;
            fun.PolyFill(dxf, list0, lineWidth, cutting);

            if (linserts[5].Y > linserts[4].Y)
            {
                LwPolyline lfiu = Pus.AddPointsToLwPolyLine(linserts[5], lhead[3], lhead[4], lhead[5], lhead[6], lhead[9], lhead[10], lhead[8]);
                lfiu.IsClosed = true;
                fun.PolyFill(dxf, lfiu, lineWidth, contour);
                LwPolyline lfcu = Pus.AddPointsToLwPolyLine(lhead[5], lhead[6], lshank[6], lshank[7]);
                lfcu.IsClosed = true;
                fun.PolyFill(dxf, lfcu, lineWidth, contour);

                LwPolyline listu = Pus.AddPointsToLwPolyLine(linserts[3], linserts[4], linserts[5]);
                listu.IsClosed = true;
                fun.PolyFill(dxf, listu, lineWidth, cutting);

            }

            //lview标注
            Vector2 list3 = Pus.ToV2(linserts[3]);
            if (lambdas == 0)
            {
                lambdas = 0.1 * pi / 180;
                Pus.NeedleDim(dxf, new Line(linserts[4], linserts[3]),
                    new Line(list3, fun.Polar(list3, Pus.AngleOnP(linserts[4], linserts[3]) + lambdas, 1)), offset * 1.3, "λs=0°", dimensionStyle);
            }
            else
            {
                Pus.NeedleDim(dxf, new Line(linserts[4], linserts[3]),
                    new Line(list3, fun.Polar(list3, Pus.AngleOnP(linserts[4], linserts[3]) + lambdas, 1)), offset * 1.3, "λs=" + Math.Round(lambdas * 180 / pi, 2) + "°", dimensionStyle);
            }
            LinearDimension dim_h2 = new LinearDimension(new Line(lshank[4], lshank[0]), offset, Pus.Degree(lshank[4], lshank[0]), dimensionStyle);
            fun.dxflinedim(dxf, dim_h2, h2);


            //图框
            Vector2 a3xsize = Frame.A3X;
            double isframe = 0;
            try
            {
                isframe = Convert.ToDouble(data["isframe"]);
            }
            catch (KeyNotFoundException) { }
            if (isframe != 0)
            {
                Vector2 EntitysCenter = new Vector2((shank[4].X + zhead[0].X) / 2, (shank[4].Y + lshank[0].Y) / 2);
                Vector2 p0 = new Vector2(EntitysCenter.X - a3xsize.X / 2, EntitysCenter.Y + a3xsize.Y / 2);
                Dictionary<string, Vector2> positions = Frame.frameA3X(dxf, p0);
                Vector2 kp = p0;
                try
                {
                    kp = positions["比例"];
                    fun.writetextofC(dxf, kscale + ":1", positions["比例"], 3.5, 0, 0.6, 3);
                }
                catch (Exception) { }
            }

            dxf.DrawingVariables.AcadVer = DxfVersion.AutoCad2007;
            dxf.Save(path);
        }
        //K型刀头 纵小
        public static void StyleK_InsertC(Dictionary<string, Object> data)
        {
            DxfDocument dxf = new DxfDocument();
            Layer contour = new Layer("contour") { Color = AciColor.Cyan };    //1,轮廓层
            Layer cutting = new Layer("cutting") { Color = AciColor.Red };    //切削层
            cutting.Lineweight = Lineweight.W200;

            string path = Convert.ToString(data["path"]);
            double pi = Math.PI;
            //参数名称取自ISO 5610
            double b = 8;
            double l1 = 100;
            double l2 = 12;
            double f = 10;
            double l3 = 6.4;
            double h2 = 8;
            double h1 = 8;
            double s = 2.38;
            double insertAngle = 100 * pi / 180;
            double alphan = 7 * pi / 180;
            double cutagl = 75 * pi / 180;
            double lambdas = 0;
            double gammao = 0;
            double repsilon = 0;
            #region
            try
            {
                if (data["re"] != null)
                    repsilon = Convert.ToDouble(data["re"]);
                if (repsilon <= 0)
                    repsilon = 0.01;
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["lams"] != null)
                    lambdas = Math.Abs(Convert.ToDouble(data["lams"]) * pi / 180);
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["gamo"] != null)
                    gammao = Math.Abs(Convert.ToDouble(data["gamo"]) * pi / 180);
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["b"] != null)
                    b = Convert.ToDouble(data["b"]);
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["s"] != null)
                    s = Convert.ToDouble(data["s"]);
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["lf"] != null)
                    l1 = Convert.ToDouble(data["lf"]);
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["lh"] != null)
                    l2 = Convert.ToDouble(data["lh"]);
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["wf"] != null)
                    f = Convert.ToDouble(data["wf"]);
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["h"] != null)
                    h2 = Convert.ToDouble(data["h"]);
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["hf"] != null)
                    h1 = Convert.ToDouble(data["hf"]);
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["epsr"] != null)
                    insertAngle = pi - Convert.ToDouble(data["epsr"]) * pi / 180;
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["kapr"] != null)
                    cutagl = Convert.ToDouble(data["kapr"]) * pi / 180;
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["an"] != null)
                    alphan = Convert.ToDouble(data["an"]) * pi / 180;
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["l"] != null)
                    l3 = Convert.ToDouble(data["l"]);
            }
            catch (KeyNotFoundException) { }
            #endregion
            double kscale = 1;
            if (l1 >= 120)
                kscale = 1;
            else
                kscale = 1.5;
            double lineWidth = 1;
            //k点位置恒定
            Vector3 k = new Vector3(0, 0, 0);
            //刀杆柄部模型
            Vector3[] shank = new Vector3[8];
            shank[4] = new Vector3(k.X + l1, k.Y + f - b, k.Z);
            shank[5] = new Vector3(shank[4].X, shank[4].Y + b, shank[4].Z);
            shank[6] = new Vector3(k.X + l2, shank[5].Y, shank[5].Z);
            shank[7] = new Vector3(shank[6].X, shank[4].Y, shank[6].Z);
            shank[0] = Pus.ToV3(shank[4], shank[4].Z - h2);
            shank[1] = Pus.ToV3(shank[5], shank[5].Z - h2);
            shank[2] = Pus.ToV3(shank[6], shank[6].Z - h2);
            shank[3] = Pus.ToV3(shank[7], shank[7].Z - h2);

            //纵向进给，主偏角小于90°：i4 = fun.Polar(k,pi/2-kapr,r*(1/tan(epsr/2) - 1/tan((pi - kapr) / 2)));
            Vector2 icorner = fun.Polar(Vector2.Zero, -cutagl, repsilon * (1 / Math.Tan(insertAngle / 2) - 1 / Math.Tan((pi - cutagl) / 2)));
            //刀片的上表面
            Vector2[] inserts2d = Pus.DiamondPoints(icorner, l3, insertAngle, false, cutagl);
            double insertOffset = Math.Tan(alphan) * s;
            //刀片下表面
            Vector2[] inserts2dd = Pus.OffsetPoints(insertOffset, inserts2d);
            //刀片模型
            Vector3[] inserts = new Vector3[inserts2d.Length * 2];
            for (int i = 0; i < inserts2d.Length; i++)
            {
                inserts[i] = Pus.ToV3(inserts2dd[i], k.Z - s);
                inserts[i + inserts2d.Length] = Pus.ToV3(inserts2d[i], k.Z);
            }
            //线性变换
            double theta = 0 * pi / 180;
            Matrix3 linearTrans = new Matrix3(
                Math.Cos(theta) * kscale, -Math.Sin(theta) * kscale, 0,
                Math.Sin(theta) * kscale, Math.Cos(theta) * kscale, 0,
                              0, 0, kscale
            );
            for (int i = 0; i < shank.Length; i++)
            {
                shank[i] = linearTrans * shank[i];
            }
            for (int i = 0; i < inserts.Length; i++)
            {
                inserts[i] = linearTrans * inserts[i];
            }
            //放倒
            Vector3 laydownV = new Vector3(-1, 0, 0);
            double laydownR = pi / 2;
            for (int i = 0; i < shank.Length; i++)
            {
                shank[i] = Pus.Rodrigue(laydownV, 1, laydownR, shank[i]);
            }
            for (int i = 0; i < inserts.Length; i++)
            {
                inserts[i] = Pus.Rodrigue(laydownV, 1, laydownR, inserts[i]);
            }

            //先创建lambdas
            Vector3 mainCutEdge = inserts[7] - inserts[4];
            double dis4s74 = Vector3.Distance(inserts[7], inserts[4]);
            //主切削刃单位向量
            Vector3 mainCutEdgeO = new Vector3(mainCutEdge.X / dis4s74, mainCutEdge.Y / dis4s74, mainCutEdge.Z / dis4s74);
            Vector3 lambdasMkr = Pus.Rodrigue(new Vector3(0, 1, 0), 1, pi / 2, mainCutEdgeO);
            for (int i = 0; i < inserts.Length; i++)
            {
                inserts[i] = Pus.Rodrigue(lambdasMkr, 1, -Math.Abs(lambdas), inserts[i]);
            }
            //创建gammao
            //变化之后的主切削刃单位向量就是产生gammao的向量
            mainCutEdge = inserts[7] - inserts[4];
            mainCutEdgeO = new Vector3(mainCutEdge.X / dis4s74, mainCutEdge.Y / dis4s74, mainCutEdge.Z / dis4s74);
            Vector3 gammaoMkr = mainCutEdgeO;
            for (int i = 0; i < inserts.Length; i++)
            {
                inserts[i] = Pus.Rodrigue(gammaoMkr, 1, -Math.Abs(lambdas), inserts[i]);
            }


            //刀头部分
            Vector3[] head = new Vector3[13];
            //insertConrnerPosition
            int icp = inserts.Length / 2;
            head[4] = Pus.KPoint(inserts[icp + 2], inserts[icp + 1], 0.91);

            head[8] = Pus.KPoint(inserts[icp + 2], inserts[icp + 3], 0.93);

            Face3d faceBottom = new Face3d(shank[0], shank[1], shank[2]);
            head[0] = Pus.Inters(faceBottom, new Line(inserts[inserts.Length / 2], inserts[0]));

            Face3d faceHeadZ = new Face3d(inserts[0], head[0], head[4]);
            head[2] = new Vector3(shank[2].X - kscale, shank[2].Y, shank[2].Z);
            head[1] = Pus.Inters(faceHeadZ, new Line(head[2], new Vector3(shank[3].X - kscale, shank[3].Y, shank[3].Z)));

            Face3d face4Con = new Face3d(new Vector3(shank[2].X - kscale, shank[2].Y, shank[2].Z), new Vector3(shank[3].X - kscale, shank[3].Y, shank[3].Z), new Vector3(shank[7].X - kscale * 1.5, shank[7].Y, shank[7].Z));
            Face3d faceInsertU = new Face3d(inserts[icp], inserts[icp + 1], inserts[icp + 2]);
            head[5] = Pus.Inters(faceInsertU, Pus.Inters(faceHeadZ, face4Con, head[1]));//head[1]所在线属于face4Con,故head[1]在该面上

            Face3d faceShankBack = new Face3d(shank[1], shank[2], shank[5]);
            head[6] = Pus.Inters(faceShankBack, Pus.Inters(faceInsertU, face4Con, head[5]));
            Face3d faceHeadX = new Face3d(head[8], inserts[0], head[0]);
            head[3] = Pus.Inters(faceShankBack, Pus.Inters(faceHeadX, faceBottom, head[0]));
            head[7] = Pus.Inters(faceShankBack, Pus.Inters(faceHeadX, faceInsertU, head[8]));

            head[9] = Pus.KPoint(head[8], head[7], 0.3);
            head[10] = Pus.KPoint(head[7], head[6], 0.3);
            head[11] = Pus.KPoint(head[3], head[0], 0.3);
            Face3d faceHeadE = new Face3d(head[9], head[10], head[11]);
            head[12] = Pus.Inters(faceHeadE, new Line(head[2], head[3]));

            //立正
            Vector3[] mshank = new Vector3[shank.Length];
            Vector3[] mhead = new Vector3[head.Length];
            Vector3[] minserts = new Vector3[inserts.Length];
            for (int i = 0; i < shank.Length; i++)
            {
                mshank[i] = Pus.Rodrigue(laydownV, 1, -laydownR, shank[i]);
            }
            for (int i = 0; i < inserts.Length; i++)
            {
                minserts[i] = Pus.Rodrigue(laydownV, 1, -laydownR, inserts[i]);
            }
            for (int i = 0; i < head.Length; i++)
            {
                mhead[i] = Pus.Rodrigue(laydownV, 1, -laydownR, head[i]);
            }
            //mview
            Vector2 mcp = Pus.IntersOnP(mshank[4], mshank[7], mhead[5], mhead[6]);
            LwPolyline mcon1 = Pus.AddPointsToLwPolyLine(mhead[6], mshank[6]);
            fun.PolyFill(dxf, mcon1, lineWidth, contour);
            LwPolyline mcon2 = Pus.AddPointsToLwPolyLine(mcp);
            Pus.AddPointsToLwPolyLine(mcon2, mshank[7]);
            fun.PolyFill(dxf, mcon2, lineWidth, contour);

            LwPolyline msk = Pus.AddPointsToLwPolyLine(mshank[7], mshank[4], mshank[5], mshank[6]);
            msk.IsClosed = true;
            fun.PolyFill(dxf, msk, lineWidth, contour);
            LwPolyline mhd = Pus.AddPointsToLwPolyLine(minserts[6], mhead[4], mhead[5], mhead[6], mhead[10], mhead[9], mhead[8]);
            mhd.IsClosed = true;
            fun.PolyFill(dxf, mhd, lineWidth, contour);

            LwPolyline mist = Pus.AddPointsToLwPolyLine(minserts[4], minserts[5], minserts[6], minserts[7]);
            mist.IsClosed = true;
            Pus.AglToArc(mist, repsilon);
            fun.PolyFill(dxf, mist, lineWidth, cutting);

            //zview
            //绕y轴旋转pi/2再平移得到左视图
            Vector3[] zshank = new Vector3[shank.Length];
            Vector3[] zhead = new Vector3[head.Length];
            Vector3[] zinserts = new Vector3[inserts.Length];
            Vector3 zviewMkr = new Vector3(0, 1, 0);
            double yR = pi / 2;
            double zoffset = -2 * b * kscale;
            for (int i = 0; i < shank.Length; i++)
            {
                zshank[i] = Pus.Rodrigue(zviewMkr, 1, yR, mshank[i]);
                zshank[i].X += zoffset;
            }
            for (int i = 0; i < inserts.Length; i++)
            {
                zinserts[i] = Pus.Rodrigue(zviewMkr, 1, yR, minserts[i]);
                zinserts[i].X += zoffset;
            }
            for (int i = 0; i < head.Length; i++)
            {
                zhead[i] = Pus.Rodrigue(zviewMkr, 1, yR, mhead[i]);
                zhead[i].X += zoffset;
            }
            LwPolyline zheadE = Pus.AddPointsToLwPolyLine(zhead[9], zhead[10], zhead[12], zhead[11]);
            zheadE.IsClosed = true;
            fun.PolyFill(dxf, zheadE, lineWidth, contour);
            LwPolyline zheadZ = Pus.AddPointsToLwPolyLine(zinserts[0], zhead[0], zhead[11], zhead[9], zhead[8]);
            fun.PolyFill(dxf, zheadZ, lineWidth, contour);
            LwPolyline zheadU = Pus.AddPointsToLwPolyLine(zhead[8], zhead[9], zhead[10], zhead[6], zhead[5], zhead[4]);
            fun.PolyFill(dxf, zheadU, lineWidth, contour);

            LwPolyline zinsertU = Pus.AddPointsToLwPolyLine(zinserts[4], zinserts[5], zinserts[6], zinserts[7]);
            zinsertU.IsClosed = true;
            fun.PolyFill(dxf, zinsertU, lineWidth, cutting);
            LwPolyline zinsertL = Pus.AddPointsToLwPolyLine(zinserts[7], zinserts[3], zinserts[0], zinserts[4]);
            fun.PolyFill(dxf, zinsertL, lineWidth, cutting);
            if (cutagl + insertAngle > pi)
            {
                LwPolyline zinsertLen = Pus.AddPointsToLwPolyLine(zinserts[0], zinserts[1], zinserts[5]);
                fun.PolyFill(dxf, zinsertLen, lineWidth, cutting);
            }


            //lview
            double lviewOffset = -h2 * 2 * kscale;
            Vector3[] lshank = new Vector3[shank.Length];
            for (int i = 0; i < shank.Length; i++)
            {
                lshank[i] = new Vector3(shank[i].X, shank[i].Y + lviewOffset, shank[i].Z);
            }
            Vector3[] linserts = new Vector3[inserts.Length];
            for (int i = 0; i < inserts.Length; i++)
            {
                linserts[i] = new Vector3(inserts[i].X, inserts[i].Y + lviewOffset, inserts[i].Z);
            }
            Vector3[] lhead = new Vector3[head.Length];
            for (int i = 0; i < head.Length; i++)
            {
                lhead[i] = new Vector3(head[i].X, head[i].Y + lviewOffset, head[i].Z);
            }

            LwPolyline lsk = Pus.AddPointsToLwPolyLine(lshank[3], lshank[0], lshank[4], lshank[7]);
            fun.PolyFill(dxf, lsk, lineWidth, contour);

            LwPolyline headBottom = Pus.AddPointsToLwPolyLine(lhead[11], lhead[0], lhead[1]);
            fun.PolyFill(dxf, headBottom, lineWidth, contour);
            LwPolyline headUpper = Pus.AddPointsToLwPolyLine(lhead[4], lhead[5], lhead[6], lhead[10], lhead[9], lhead[8]);
            fun.PolyFill(dxf, headUpper, lineWidth, contour);
            LwPolyline hlen1 = Pus.AddPointsToLwPolyLine(linserts[0], lhead[0]);
            fun.PolyFill(dxf, hlen1, lineWidth, contour);
            LwPolyline hlen2 = Pus.AddPointsToLwPolyLine(lhead[1], lhead[5]);
            fun.PolyFill(dxf, hlen2, lineWidth, contour);

            Vector2 mec1 = Pus.IntersOnP(lhead[9], lhead[11], linserts[6], linserts[7]);
            Vector2 mec2 = Pus.IntersOnP(lhead[9], lhead[11], linserts[0], linserts[3]);
            LwPolyline hlen3 = Pus.AddPointsToLwPolyLine(mec2, lhead[11]);
            fun.PolyFill(dxf, hlen3, lineWidth, contour);
            LwPolyline hlen4 = Pus.AddPointsToLwPolyLine(mec1, lhead[9]);
            fun.PolyFill(dxf, hlen4, lineWidth, contour);

            LwPolyline lcon1 = Pus.AddPointsToLwPolyLine(lhead[5], lshank[7]);
            fun.PolyFill(dxf, lcon1, lineWidth, contour);
            LwPolyline lcon2 = Pus.AddPointsToLwPolyLine(lhead[1], lshank[3]);
            fun.PolyFill(dxf, lcon2, lineWidth, contour);

            LwPolyline lintu = Pus.AddPointsToLwPolyLine(linserts[4], linserts[5], linserts[6], linserts[7]);
            lintu.IsClosed = true;
            fun.PolyFill(dxf, lintu, lineWidth, cutting);

            LwPolyline lintb = Pus.AddPointsToLwPolyLine(linserts[3], linserts[0], linserts[1]);
            fun.PolyFill(dxf, lintb, lineWidth, cutting);
            LwPolyline line = Pus.AddPointsToLwPolyLine(linserts[0], linserts[4]);
            fun.PolyFill(dxf, line, lineWidth, cutting);
            LwPolyline line1 = Pus.AddPointsToLwPolyLine(linserts[3], linserts[7]);
            fun.PolyFill(dxf, line1, lineWidth, cutting);
            LwPolyline line2 = Pus.AddPointsToLwPolyLine(linserts[1], linserts[5]);
            fun.PolyFill(dxf, line2, lineWidth, cutting);

            //图框
            Vector2 a3xsize = Frame.A3X;
            double isframe = 0;
            try
            {
                isframe = Convert.ToDouble(data["isframe"]);
            }
            catch (KeyNotFoundException) { }
            if (isframe != 0)
            {
                Vector2 EntitysCenter = new Vector2((mshank[4].X + zhead[0].X) / 2, (mshank[4].Y + lshank[0].Y) / 2);
                Vector2 p0 = new Vector2(EntitysCenter.X - a3xsize.X / 2, EntitysCenter.Y + a3xsize.Y / 2);
                Dictionary<string, Vector2> positions = Frame.frameA3X(dxf, p0);
                Vector2 kp = p0;
                try
                {
                    kp = positions["比例"];
                    fun.writetextofC(dxf, kscale + ":1", positions["比例"], 3.5, 0, 0.6, 3);
                }
                catch (Exception) { }
            }

            dxf.DrawingVariables.AcadVer = DxfVersion.AutoCad2007;
            dxf.Save(path);
        }
        public static void StyleK_InsertS(Dictionary<string, Object> data)
        {
            DxfDocument dxf = new DxfDocument();
            Layer contour = new Layer("contour") { Color = AciColor.Cyan };    //1,轮廓层
            Layer cutting = new Layer("cutting") { Color = AciColor.Red };    //切削层
            cutting.Lineweight = Lineweight.W200;

            string path = Convert.ToString(data["path"]);
            //参数名称取自ISO 5610
            double a = 1.6;
            double b = 12;
            double l1 = 100;
            double l2 = 32;
            double f = 16;
            double l3 = 9.52;
            double h2 = 12;
            double h1 = 12;
            double s = 3.97;
            double insertAngle = 90 * pi / 180;
            double alphan = 0 * pi / 180;
            double cutagl = 75 * pi / 180;
            double lambdas = 0;
            double gammao = 0;
            double repsilon = 0;
            #region
            try
            {
                if (data["lfa"] != null)
                    a = Math.Abs(Convert.ToDouble(data["lfa"]) * pi / 180);
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["re"] != null)
                    repsilon = Convert.ToDouble(data["re"]);
                if (repsilon <= 0)
                    repsilon = 0.01;
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["lams"] != null)
                    lambdas = Math.Abs(Convert.ToDouble(data["lams"]) * pi / 180);
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["gamo"] != null)
                    gammao = Math.Abs(Convert.ToDouble(data["gamo"]) * pi / 180);
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["b"] != null)
                    b = Convert.ToDouble(data["b"]);
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["s"] != null)
                    s = Convert.ToDouble(data["s"]);
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["lf"] != null)
                    l1 = Convert.ToDouble(data["lf"]);
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["lh"] != null)
                    l2 = Convert.ToDouble(data["lh"]);
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["wf"] != null)
                    f = Convert.ToDouble(data["wf"]);
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["h"] != null)
                    h2 = Convert.ToDouble(data["h"]);
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["hf"] != null)
                    h1 = Convert.ToDouble(data["hf"]);
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["epsr"] != null)
                    insertAngle = Convert.ToDouble(data["epsr"]) * pi / 180;
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["kapr"] != null)
                    cutagl = Convert.ToDouble(data["kapr"]) * pi / 180;
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["an"] != null)
                    alphan = Convert.ToDouble(data["an"]) * pi / 180;
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["ic"] != null)
                    l3 = Pus.GetLByIC(Convert.ToDouble(data["ic"]), insertAngle);
            }
            catch (KeyNotFoundException) { }
            #endregion
            double kscale = 1;
            if (l1 >= 120)
                kscale = 1;
            else
                kscale = 1.5;
            double lineWidth = 1;
            //k点位置恒定
            Vector3 k = new Vector3(0, 0, 0);
            //刀杆柄部模型
            Vector3[] shank = new Vector3[8];
            shank[4] = new Vector3(k.X + l1, k.Y + f - b, k.Z);
            shank[5] = new Vector3(shank[4].X, shank[4].Y + b, shank[4].Z);
            shank[6] = new Vector3(k.X - a + l2, shank[5].Y, shank[5].Z);
            shank[7] = new Vector3(shank[6].X, shank[4].Y, shank[6].Z);
            shank[0] = Pus.ToV3(shank[4], shank[4].Z - h2);
            shank[1] = Pus.ToV3(shank[5], shank[5].Z - h2);
            shank[2] = Pus.ToV3(shank[6], shank[6].Z - h2);
            shank[3] = Pus.ToV3(shank[7], shank[7].Z - h2);

            //纵向进给，主偏角小于90°：i4 = fun.Polar(k,pi/2-kapr,r*(1/tan(epsr/2) - 1/tan((pi - kapr) / 2)));
            Vector2 icorner = fun.Polar(Vector2.Zero, -cutagl, repsilon * (1 / Math.Tan(insertAngle / 2) - 1 / Math.Tan((pi - cutagl) / 2)));
            //刀片的上表面
            Vector2[] inserts2d = Pus.DiamondPoints(icorner, l3, insertAngle, false, cutagl);
            double insertOffset = Math.Tan(alphan) * s;
            //刀片下表面
            Vector2[] inserts2dd = Pus.OffsetPoints(insertOffset, inserts2d);
            //刀片模型
            Vector3[] inserts = new Vector3[inserts2d.Length * 2];
            for (int i = 0; i < inserts2d.Length; i++)
            {
                inserts[i] = Pus.ToV3(inserts2dd[i], k.Z - s);
                inserts[i + inserts2d.Length] = Pus.ToV3(inserts2d[i], k.Z);
            }
            //线性变换
            double theta = 0 * pi / 180;
            Matrix3 linearTrans = new Matrix3(
                Math.Cos(theta) * kscale, -Math.Sin(theta) * kscale, 0,
                Math.Sin(theta) * kscale, Math.Cos(theta) * kscale, 0,
                              0, 0, kscale
            );
            for (int i = 0; i < shank.Length; i++)
            {
                shank[i] = linearTrans * shank[i];
            }
            for (int i = 0; i < inserts.Length; i++)
            {
                inserts[i] = linearTrans * inserts[i];
            }
            //放倒
            Vector3 laydownV = new Vector3(-1, 0, 0);
            double laydownR = pi / 2;
            for (int i = 0; i < shank.Length; i++)
            {
                shank[i] = Pus.Rodrigue(laydownV, 1, laydownR, shank[i]);
            }
            for (int i = 0; i < inserts.Length; i++)
            {
                inserts[i] = Pus.Rodrigue(laydownV, 1, laydownR, inserts[i]);
            }

            //先创建lambdas
            Vector3 mainCutEdge = inserts[7] - inserts[4];
            double dis4s74 = Vector3.Distance(inserts[7], inserts[4]);
            //主切削刃单位向量
            Vector3 mainCutEdgeO = new Vector3(mainCutEdge.X / dis4s74, mainCutEdge.Y / dis4s74, mainCutEdge.Z / dis4s74);
            Vector3 lambdasMkr = Pus.Rodrigue(new Vector3(0, 1, 0), 1, pi / 2, mainCutEdgeO);
            for (int i = 0; i < inserts.Length; i++)
            {
                inserts[i] = Pus.Rodrigue(lambdasMkr, 1, -Math.Abs(lambdas), inserts[i]);
            }
            //创建gammao
            //变化之后的主切削刃单位向量就是产生gammao的向量
            Vector3 gammaoMkr = Pus.UnitVector(inserts[4], inserts[7]);
            for (int i = 0; i < inserts.Length; i++)
            {
                inserts[i] = Pus.Rodrigue(gammaoMkr, 1, -Math.Abs(gammao), inserts[i]);
            }


            //刀头部分
            Vector3[] head = new Vector3[17];
            //insertConrnerPosition
            //垂直基面向上的单位向量
            Vector3 upn = Pus.UnitVector(shank[0], shank[4]);
            int icp = inserts.Length / 2;
            //已知的面
            Face3d fiu = new Face3d(inserts[icp], inserts[icp + 1], inserts[icp + 2]);
            Face3d fib = new Face3d(inserts[0], inserts[1], inserts[2]);
            Face3d fbk = new Face3d(shank[1], shank[2], shank[6]);
            Face3d fb = new Face3d(shank[0], shank[1], shank[2]);

            head[0] = Pus.Inters(fb, new Line(inserts[inserts.Length / 2], inserts[0]));
            head[12] = Pus.KPoint(inserts[icp + 2], inserts[icp + 3], 0.93);
            head[6] = Pus.KPoint(inserts[icp + 2], inserts[icp + 1], 0.93);

            Vector3 head7mkr = Pus.UnitNormal(new Face3d(inserts[icp], inserts[icp + 1], inserts[icp + 3]));
            //以head[6]为原点旋转，要将被旋转点移动到以其为原点的位置，旋转完后再平移回去
            head[7] = Pus.Rodrigue(head7mkr, 1, pi / 3, Pus.KPoint(inserts[icp + 2], inserts[icp + 1], 1) - head[6]) + head[6];
            Face3d fd0 = new Face3d(head[0], inserts[0], inserts[1]);
            head[1] = Pus.Inters(fb, new Line(inserts[1], inserts[5]));
            Face3d fr11 = new Face3d(head[1], inserts[1], shank[0]);

            Face3d fcon = new Face3d(shank[2], shank[3], new Vector3(shank[7].X - kscale, shank[7].Y, shank[7].Z));

            head[2] = Pus.Inters(fr11, new Line(shank[2], shank[3]));

            head[3] = shank[2];

            Face3d fd1 = new Face3d(head[0], inserts[0], head[12]);
            head[16] = Pus.Inters(fd1, new Line(shank[1], shank[2]));
            head[15] = Pus.Inters(fiu, Pus.Inters(fd1, fbk, head[16]));
            head[5] = Pus.KPoint(head[16], head[0], 0.3);
            head[4] = Pus.KPoint(head[16], head[3], 0.3);
            head[11] = Pus.KPoint(head[12], head[15], 0.3);
            Face3d fe = new Face3d(head[4], head[5], head[11]);
            head[10] = Pus.Inters(fiu, Pus.Inters(fe, fbk, head[4]));
            head[9] = Pus.Inters(fiu, Pus.Inters(fbk, fcon, head[3]));
            head[8] = Pus.Inters(fiu, Pus.Inters(fr11, fcon, head[2]));
            Face3d fc = new Face3d(head[6], head[7], head[6] + upn);

            head[13] = Pus.Inters(fc, new Line(inserts[1], inserts[2]));
            Vector3 head14mkr = new Vector3(head[13].X + (head[7] - head[6]).X, head[13].Y, head[13].Z + (head[7] - head[6]).Z);
            head[14] = Pus.Inters(fr11, new Line(head[13], head14mkr));

            //立正
            Vector3[] mshank = new Vector3[shank.Length];
            Vector3[] mhead = new Vector3[head.Length];
            Vector3[] minserts = new Vector3[inserts.Length];
            for (int i = 0; i < shank.Length; i++)
            {
                mshank[i] = Pus.Rodrigue(laydownV, 1, -laydownR, shank[i]);
            }
            for (int i = 0; i < inserts.Length; i++)
            {
                minserts[i] = Pus.Rodrigue(laydownV, 1, -laydownR, inserts[i]);
            }
            for (int i = 0; i < head.Length; i++)
            {
                mhead[i] = Pus.Rodrigue(laydownV, 1, -laydownR, head[i]);
            }
            //mview
            Vector2 mcp = Pus.IntersOnP(mshank[4], mshank[7], mhead[8], mhead[9]);
            LwPolyline mcon1 = Pus.AddPointsToLwPolyLine(mhead[9], mshank[6]);
            fun.PolyFill(dxf, mcon1, lineWidth, contour);
            LwPolyline mcon2 = Pus.AddPointsToLwPolyLine(mcp);
            Pus.AddPointsToLwPolyLine(mcon2, mshank[7]);
            fun.PolyFill(dxf, mcon2, lineWidth, contour);

            LwPolyline msk = Pus.AddPointsToLwPolyLine(mshank[7], mshank[4], mshank[5], mshank[6]);
            msk.IsClosed = true;
            fun.PolyFill(dxf, msk, lineWidth, contour);
            LwPolyline mhd = Pus.AddPointsToLwPolyLine(minserts[6], mhead[6], mhead[7], mhead[8], mhead[9], mhead[10], mhead[11], mhead[12]);
            mhd.IsClosed = true;
            fun.PolyFill(dxf, mhd, lineWidth, contour);

            LwPolyline mist = Pus.AddPointsToLwPolyLine(minserts[4], minserts[5], minserts[6], minserts[7]);
            mist.IsClosed = true;
            Pus.AglToArc(mist, repsilon);
            fun.PolyFill(dxf, mist, lineWidth, cutting);
            //mview标注
            DimensionStyle dimensionStyle = new DimensionStyle("mystyle");
            dimensionStyle.ArrowSize = kscale * 1.2;
            dimensionStyle.DimArrow1 = DimensionArrowhead.Closedfilled;
            dimensionStyle.DimArrow2 = DimensionArrowhead.Closedfilled;
            dimensionStyle.TextHeight = kscale * 2;
            dimensionStyle.TextOffset = kscale / 2;
            double offset = 7 * kscale;
            LinearDimension dim_f = new LinearDimension(new Line(Vector3.Zero, mhead[10]), offset * 2, Pus.Degree(mshank[4], mshank[5]), dimensionStyle);
            fun.dxflinedim(dxf, dim_f, f);
            LinearDimension dim_l1 = new LinearDimension(new Line(Vector3.Zero, mshank[4]), offset * 2, 180, dimensionStyle);
            fun.dxflinedim(dxf, dim_l1, l1);
            Arc iarc4 = Pus.GetArcFromPline(mist, 4);
            LinearDimension dim_l2 = new LinearDimension(new Line(new Vector2(iarc4.Center.X - repsilon, iarc4.Center.Y), Pus.ToV2(mshank[6])), offset * 2.5, 0, dimensionStyle);
            fun.dxflinedim(dxf, dim_l2, l2);
            LinearDimension dim_b = new LinearDimension(new Line(mshank[4], mshank[5]), offset * 2, -90, dimensionStyle);
            fun.dxflinedim(dxf, dim_b, b);
            Angular2LineDimension dim_cutagl = new Angular2LineDimension(new Line(Pus.ToV2(minserts[icp]), fun.Polar(Pus.ToV2(minserts[icp]), pi, 1)), new Line(minserts[icp], minserts[icp + 3]), offset * 0.8, dimensionStyle);
            dim_cutagl.UserText = Math.Round(cutagl * 180 / pi, 2) + "°";
            dxf.AddEntity(dim_cutagl);
            RadialDimension dim_repsilon = new RadialDimension(Pus.GetArcFromPline(mist, 1), Pus.Degree(minserts[icp + 3], minserts[icp]) - 45, offset * 0.5, dimensionStyle);
            dim_repsilon.UserText = "rε=" + repsilon;
            dxf.AddEntity(dim_repsilon);

            //zview
            //绕y轴旋转pi/2再平移得到左视图
            Vector3[] zshank = new Vector3[shank.Length];
            Vector3[] zhead = new Vector3[head.Length];
            Vector3[] zinserts = new Vector3[inserts.Length];
            Vector3 zviewMkr = new Vector3(0, 1, 0);
            double yR = pi / 2;
            double zoffset = -2 * b * kscale;
            for (int i = 0; i < shank.Length; i++)
            {
                zshank[i] = Pus.Rodrigue(zviewMkr, 1, yR, mshank[i]);
                zshank[i].X += zoffset;
            }
            for (int i = 0; i < inserts.Length; i++)
            {
                zinserts[i] = Pus.Rodrigue(zviewMkr, 1, yR, minserts[i]);
                zinserts[i].X += zoffset;
            }
            for (int i = 0; i < head.Length; i++)
            {
                zhead[i] = Pus.Rodrigue(zviewMkr, 1, yR, mhead[i]);
                zhead[i].X += zoffset;
            }
            Vector3 zk = k;
            zk.X += zoffset;
            LwPolyline zheadE = Pus.AddPointsToLwPolyLine(zhead[10], zhead[11], zhead[5], zhead[4]);
            zheadE.IsClosed = true;
            fun.PolyFill(dxf, zheadE, lineWidth, contour);
            LwPolyline zheadZ = Pus.AddPointsToLwPolyLine(zinserts[0], zhead[0], zhead[5], zhead[11], zhead[12]);
            fun.PolyFill(dxf, zheadZ, lineWidth, contour);
            LwPolyline zheadU = Pus.AddPointsToLwPolyLine(zhead[6], zhead[7], zhead[8], zhead[9], zhead[10], zhead[11], zhead[12]);
            fun.PolyFill(dxf, zheadU, lineWidth, contour);

            LwPolyline zinsertU = Pus.AddPointsToLwPolyLine(zinserts[4], zinserts[5], zinserts[6], zinserts[7]);
            zinsertU.IsClosed = true;
            fun.PolyFill(dxf, zinsertU, lineWidth, cutting);
            LwPolyline zinsertL = Pus.AddPointsToLwPolyLine(zinserts[7], zinserts[3], zinserts[0], zinserts[4]);
            fun.PolyFill(dxf, zinsertL, lineWidth, cutting);
            if (cutagl + insertAngle > pi)
            {
                LwPolyline zinsertLen = Pus.AddPointsToLwPolyLine(zinserts[0], zinserts[1], zinserts[5]);
                fun.PolyFill(dxf, zinsertLen, lineWidth, cutting);
            }
            //zview标注
            if (lambdas == 0)
            {
                lambdas = 0.5 * pi / 180;
                Pus.NeedleDim(dxf, new Line(Pus.ToV2(zinserts[4]), fun.Polar(Pus.ToV2(zinserts[4]), -pi / 2, 1)),
                    new Line(Pus.ToV2(zinserts[4]), fun.Polar(Pus.ToV2(zinserts[4]), -pi / 2 - lambdas, 1)), offset, "λs=0°", dimensionStyle);
            }
            else
            {
                Pus.NeedleDim(dxf, new Line(Pus.ToV2(zinserts[4]), fun.Polar(Pus.ToV2(zinserts[4]), -pi / 2, 1)),
                    new Line(Pus.ToV2(zinserts[4]), fun.Polar(Pus.ToV2(zinserts[4]), -pi / 2 - lambdas, 1)), offset, "λs=" + Math.Round(lambdas * 180 / pi, 2) + "°", dimensionStyle);
            }

            //lview
            double lviewOffset = -h2 * 2 * kscale;
            Vector3[] lshank = new Vector3[shank.Length];
            for (int i = 0; i < shank.Length; i++)
            {
                lshank[i] = new Vector3(shank[i].X, shank[i].Y + lviewOffset, shank[i].Z);
            }
            Vector3[] linserts = new Vector3[inserts.Length];
            for (int i = 0; i < inserts.Length; i++)
            {
                linserts[i] = new Vector3(inserts[i].X, inserts[i].Y + lviewOffset, inserts[i].Z);
            }
            Vector3[] lhead = new Vector3[head.Length];
            for (int i = 0; i < head.Length; i++)
            {
                lhead[i] = new Vector3(head[i].X, head[i].Y + lviewOffset, head[i].Z);
            }
            Vector3 lk = k;
            lk.Y += lviewOffset;

            LwPolyline lsk = Pus.AddPointsToLwPolyLine(lshank[3], lshank[0], lshank[4], lshank[7]);
            fun.PolyFill(dxf, lsk, lineWidth, contour);


            LwPolyline headBottom = Pus.AddPointsToLwPolyLine(lhead[5], lhead[0], lhead[1], lhead[2], lhead[8]);
            fun.PolyFill(dxf, headBottom, lineWidth, contour);
            LwPolyline headUpper = Pus.AddPointsToLwPolyLine(lhead[6], lhead[7], lhead[8], lhead[9], lhead[10], lhead[11], lhead[12]);
            fun.PolyFill(dxf, headUpper, lineWidth, contour);
            LwPolyline hlen1 = Pus.AddPointsToLwPolyLine(linserts[0], lhead[0]);
            fun.PolyFill(dxf, hlen1, lineWidth, contour);
            LwPolyline hlen2 = Pus.AddPointsToLwPolyLine(linserts[1], lhead[1]);
            fun.PolyFill(dxf, hlen2, lineWidth, contour);


            Vector2 mec1 = Pus.IntersOnP(lhead[5], lhead[11], linserts[6], linserts[7]);
            Vector2 mec2 = Pus.IntersOnP(lhead[5], lhead[11], linserts[0], linserts[3]);
            if (mec1.X < inserts[7].X && mec2.X < inserts[3].X)
            {
                LwPolyline full = Pus.AddPointsToLwPolyLine(lhead[5], lhead[11]);
                fun.PolyFill(dxf, full, lineWidth, contour);
            }
            else
            {

                LwPolyline hlen3 = Pus.AddPointsToLwPolyLine(mec2, lhead[5]);
                fun.PolyFill(dxf, hlen3, lineWidth, contour);
                LwPolyline hlen4 = Pus.AddPointsToLwPolyLine(mec1, lhead[11]);
                fun.PolyFill(dxf, hlen4, lineWidth, contour);
            }

            LwPolyline lcon1 = Pus.AddPointsToLwPolyLine(lhead[8], lshank[7]);
            fun.PolyFill(dxf, lcon1, lineWidth, contour);
            LwPolyline lcon2 = Pus.AddPointsToLwPolyLine(lhead[2], lshank[3]);
            fun.PolyFill(dxf, lcon2, lineWidth, contour);

            LwPolyline lintu = Pus.AddPointsToLwPolyLine(linserts[4], linserts[5], linserts[6], linserts[7]);
            lintu.IsClosed = true;
            fun.PolyFill(dxf, lintu, lineWidth, cutting);

            LwPolyline lintb = Pus.AddPointsToLwPolyLine(linserts[3], linserts[0], linserts[1]);
            fun.PolyFill(dxf, lintb, lineWidth, cutting);
            LwPolyline line = Pus.AddPointsToLwPolyLine(linserts[0], linserts[4]);
            fun.PolyFill(dxf, line, lineWidth, cutting);
            LwPolyline line1 = Pus.AddPointsToLwPolyLine(linserts[3], linserts[7]);
            fun.PolyFill(dxf, line1, lineWidth, cutting);
            LwPolyline line2 = Pus.AddPointsToLwPolyLine(linserts[1], linserts[5]);
            fun.PolyFill(dxf, line2, lineWidth, cutting);
            //mview标注
            LinearDimension dim_h2 = new LinearDimension(new Line(lshank[4], lshank[0]), offset * 2, Pus.Degree(lshank[4], lshank[0]), dimensionStyle);
            fun.dxflinedim(dxf, dim_h2, h2);
            LinearDimension dim_h1 = new LinearDimension(new Line(lhead[0], lk), offset, Pus.Degree(lshank[0], lshank[4]), dimensionStyle);
            fun.dxflinedim(dxf, dim_h1, h1);
            if (gammao == 0)
            {
                gammao = 0.1 * pi / 180;
                Pus.NeedleDim(dxf, new Line(Pus.ToV2(linserts[4]), fun.Polar(Pus.ToV2(linserts[4]), pi, 1)),
                    new Line(Pus.ToV2(linserts[4]), fun.Polar(Pus.ToV2(linserts[4]), pi + gammao, 1)), offset * 1.5, "γo=0°", dimensionStyle);
            }
            else
            {
                Pus.NeedleDim(dxf, new Line(Pus.ToV2(linserts[4]), fun.Polar(Pus.ToV2(linserts[4]), pi, 1)),
                    new Line(Pus.ToV2(linserts[4]), fun.Polar(Pus.ToV2(linserts[4]), pi + gammao, 1)), offset * 1.5, "γo=" + Math.Round(gammao * 180 / pi, 2) + "°", dimensionStyle);
            }

            //图框
            Vector2 a3xsize = Frame.A3X;
            double isframe = 0;
            try
            {
                isframe = Convert.ToDouble(data["isframe"]);
            }
            catch (KeyNotFoundException) { }
            if (isframe != 0)
            {
                Vector2 EntitysCenter = new Vector2((mshank[4].X + zhead[0].X) / 2, (mshank[4].Y + lshank[0].Y) / 2);
                Vector2 p0 = new Vector2(EntitysCenter.X - a3xsize.X / 2, EntitysCenter.Y + a3xsize.Y / 2);
                Dictionary<string, Vector2> positions = Frame.frameA3X(dxf, p0);
                Vector2 kp = p0;
                try
                {
                    kp = positions["比例"];
                    fun.writetextofC(dxf, kscale + ":1", positions["比例"], 3.5, 0, 0.6, 3);
                }
                catch (Exception) { }
            }

            dxf.DrawingVariables.AcadVer = DxfVersion.AutoCad2007;
            dxf.Save(path);
        }
        //L型刀头 横大
        public static void StyleL_InsertC(Dictionary<string, Object> data)
        {
            DxfDocument dxf = new DxfDocument();
            Layer contour = new Layer("contour") { Color = AciColor.Cyan };    //1,轮廓层
            Layer cutting = new Layer("cutting") { Color = AciColor.Red };    //切削层

            string path = Convert.ToString(data["path"]);
            //参数名称取自ISO 5610
            double b = 8;
            double l1 = 100;
            double l2 = 12;
            double f = 10;
            double l3 = 6.4;
            double h2 = 8;
            double h1 = 8;
            double s = 2.38;
            double insertAngle = 80 * pi / 180;
            double alphan = 0 * pi / 180;
            double cutagl = 95 * pi / 180;
            double lambdas = 0;
            double gamao = 0;
            double repsilon = 0;
            #region
            try
            {
                if (data["re"] != null)
                    repsilon = Convert.ToDouble(data["re"]);
                if (repsilon <= 0)
                    repsilon = 0.01;
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["lams"] != null)
                    lambdas = Math.Abs(Convert.ToDouble(data["lams"]) * pi / 180);
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["gamo"] != null)
                    gamao = Math.Abs(Convert.ToDouble(data["gamo"]) * pi / 180);
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["b"] != null)
                    b = Convert.ToDouble(data["b"]);
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["s"] != null)
                    s = Convert.ToDouble(data["s"]);
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["lf"] != null)
                    l1 = Convert.ToDouble(data["lf"]);
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["lh"] != null)
                    l2 = Convert.ToDouble(data["lh"]);
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["wf"] != null)
                    f = Convert.ToDouble(data["wf"]);
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["h"] != null)
                    h2 = Convert.ToDouble(data["h"]);
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["hf"] != null)
                    h1 = Convert.ToDouble(data["hf"]);
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["epsr"] != null)
                    insertAngle = Convert.ToDouble(data["epsr"]) * pi / 180;
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["kapr"] != null)
                    cutagl = Convert.ToDouble(data["kapr"]) * pi / 180;
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["an"] != null)
                    alphan = Convert.ToDouble(data["an"]) * pi / 180;
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["ic"] != null)
                    l3 = Convert.ToDouble(data["l"]);
            }
            catch (KeyNotFoundException) { }
            #endregion
            //线性变换
            Vector2 zero = new Vector2(0, 0);
            double kscale = 1;
            if (l1 >= 120)
                kscale = 1;
            else
                kscale = 1.5;
            double lineWidth = 1;
            //k点位置恒定
            Vector3 k = new Vector3(0, 0, 0);
            Vector3 b2 = new Vector3(k.X + l1, k.Y + f, k.Z - h1);
            Vector3 b1 = new Vector3(b2.X, b2.Y - b, b2.Z);
            Vector3 b6 = new Vector3(k.X + l2, b1.Y, b1.Z);

            //刀杆顶面
            Vector3 u1 = new Vector3(b1.X, b1.Y, b1.Z + h2);
            Vector3 u2 = new Vector3(b2.X, b2.Y, b2.Z + h2);
            Vector3 u3 = new Vector3(b6.X, b2.Y, b2.Z + h2);
            double guai = kscale;
            Vector3 u3p = new Vector3(u3.X - guai, u3.Y, u3.Z);
            Vector3 u4 = new Vector3(b6.X, b6.Y, b6.Z + h2);
            Vector3 u4p = new Vector3(u4.X - guai, u4.Y, u4.Z);

            //前角与刃倾角都为0时刀尖点与k的关系,"纵向进给，主偏角大于90°k点与i4的关系"
            Vector2 cen = fun.Polar(new Vector2(k.X, k.Y), pi / 4, repsilon / Math.Sin(pi / 4));
            Vector2 twoi4 = fun.Polar(cen, 2 * pi - cutagl - insertAngle / 2, repsilon / Math.Sin(insertAngle / 2));
            Vector2[] twois = Pus.DiamondPoints(twoi4, l3, insertAngle, false, cutagl);
            Vector2 twoi1 = twois[1];
            Vector2 twoi2 = twois[2];
            Vector2 twoi3 = twois[3];
            double theoffset = Math.Tan(alphan) * s;
            Vector2[] twoiis = Pus.OffsetPoints(theoffset, twois);
            Vector2 twoii4 = twoiis[0];
            Vector2 twoii3 = twoiis[3];
            Vector2 twoii1 = twoiis[1];
            Vector2 twoii2 = twoiis[2];

            //刀头面
            Vector3 i4 = new Vector3(twoi4.X, twoi4.Y, k.Z);
            Vector3 i3 = new Vector3(twoi3.X, twoi3.Y, k.Z);
            Vector3 i2 = new Vector3(twoi2.X, twoi2.Y, k.Z);
            Vector3 i1 = new Vector3(twoi1.X, twoi1.Y, k.Z);
            Vector2 x = Pus.IntersOnP(i4, i1, u3p, u4p);
            Vector3 dt1 = new Vector3(x.X, x.Y, u4.Z);
            Vector3 dt2 = u3p;
            Vector2 xx = Pus.IntersOnP(i3, i4, u2, u3);
            Vector3 dt4 = Pus.KPoint(i3, new Vector3(xx.X, xx.Y, u3.Z), 0.7);
            Vector3 dt3 = Pus.KPoint(u3, new Vector3(xx.X, xx.Y, u3.Z), 0.85);

            Vector3 b5 = new Vector3(twoii4.X, twoii4.Y, b1.Z);
            Vector3 b4 = new Vector3(dt4.X, dt4.Y, b1.Z);
            Vector3 b3 = new Vector3(dt3.X, dt3.Y, b1.Z);

            Vector3 ii4 = new Vector3(twoii4.X, twoii4.Y, k.Z - s);
            Vector3 ii3 = new Vector3(twoii3.X, twoii3.Y, k.Z - s);
            Vector3 ii1 = new Vector3(twoii1.X, twoii1.Y, k.Z - s);
            Vector3 ii2 = new Vector3(twoii2.X, twoii2.Y, k.Z - s);

            i4 = Pus.LinearTrans(kscale, i4);
            i3 = Pus.LinearTrans(kscale, i3);
            i2 = Pus.LinearTrans(kscale, i2);
            i1 = Pus.LinearTrans(kscale, i1);
            dt1 = Pus.LinearTrans(kscale, dt1);
            dt2 = Pus.LinearTrans(kscale, dt2);
            dt3 = Pus.LinearTrans(kscale, dt3);
            dt4 = Pus.LinearTrans(kscale, dt4);
            ii4 = Pus.LinearTrans(kscale, ii4);
            ii3 = Pus.LinearTrans(kscale, ii3);
            ii2 = Pus.LinearTrans(kscale, ii2);
            ii1 = Pus.LinearTrans(kscale, ii1);

            b1 = Pus.LinearTrans(kscale, b1);
            b2 = Pus.LinearTrans(kscale, b2);
            b3 = Pus.LinearTrans(kscale, b3);
            b4 = Pus.LinearTrans(kscale, b4);
            b5 = Pus.LinearTrans(kscale, b5);
            b6 = Pus.LinearTrans(kscale, b6);

            u1 = Pus.LinearTrans(kscale, u1);
            u2 = Pus.LinearTrans(kscale, u2);
            u3 = Pus.LinearTrans(kscale, u3);
            u3p = Pus.LinearTrans(kscale, u3p);
            u4 = Pus.LinearTrans(kscale, u4);

            //主视图
            LwPolyline mshank = Pus.AddPointsToLwPolyLine(u1, u2, u3, u4);
            mshank.IsClosed = true;
            fun.PolyFill(dxf, mshank, lineWidth, contour);

            LwPolyline minsert = Pus.AddPointsToLwPolyLine(i4, i1, i2, i3);
            minsert.IsClosed = true;
            Pus.AglToArc(minsert, repsilon);
            Vector2 vertex2 = minsert.Vertexes[2].Position;
            Vector2 vertex7 = minsert.Vertexes[7].Position;

            LwPolyline mhead = Pus.AddPointsToLwPolyLine(new Vector3(vertex2.X, vertex2.Y, 0.0), dt1, dt2, dt3, dt4, new Vector3(vertex7.X, vertex7.Y, 0.0));
            fun.PolyFill(dxf, mhead, lineWidth, contour);
            LwPolyline mheadc1 = Pus.AddPointsToLwPolyLine(dt1, u4);
            fun.PolyFill(dxf, mheadc1, lineWidth, contour);
            LwPolyline mheadc2 = Pus.AddPointsToLwPolyLine(dt2, u3);
            fun.PolyFill(dxf, mheadc2, lineWidth, contour);

            fun.PolyFill(dxf, minsert, lineWidth, cutting);
            //主视图标注
            DimensionStyle dimensionStyle = new DimensionStyle("mystyle");
            dimensionStyle.ArrowSize = kscale * 1.2;
            dimensionStyle.DimArrow1 = DimensionArrowhead.Closedfilled;
            dimensionStyle.DimArrow2 = DimensionArrowhead.Closedfilled;
            dimensionStyle.TextHeight = kscale * 1.7;
            dimensionStyle.TextOffset = kscale / 2;
            double offset = 7 * kscale;
            LinearDimension dim_f = new LinearDimension(new Line(new Vector2(k.X, k.Y), new Vector2(b3.X, b3.Y)), offset * 1.5, Pus.Degree(b1, b2), dimensionStyle);
            fun.dxflinedim(dxf, dim_f, f);
            LinearDimension dim_l1 = new LinearDimension(new Line(new Vector2(k.X, k.Y), new Vector2(b1.X, b1.Y)), offset, Pus.Degree(new Vector2(b1.X, b1.Y), new Vector2(b6.X, b6.Y)), dimensionStyle);
            fun.dxflinedim(dxf, dim_l1, l1);
            LinearDimension dim_l2 = new LinearDimension(new Line(new Vector2(k.X, k.Y), new Vector2(u4.X, u4.Y)), offset * 0.7, Pus.Degree(new Vector2(u1.X, u1.Y), new Vector2(u4.X, u4.Y)), dimensionStyle);
            fun.dxflinedim(dxf, dim_l2, l2);
            LinearDimension dim_l3 = new LinearDimension(new Line(i2, i1), offset * 0.6, Pus.Degree(new Vector2(i2.X, i2.Y), new Vector2(i1.X, i1.Y)), dimensionStyle);
            fun.dxflinedim(dxf, dim_l3, Math.Round(l3, 2));
            LinearDimension dim_b = new LinearDimension(new Line(new Vector2(u1.X, u1.Y), new Vector2(u2.X, u2.Y)), offset, Pus.Degree(new Vector2(u2.X, u2.Y), new Vector2(u1.X, u1.Y)), dimensionStyle);
            fun.dxflinedim(dxf, dim_b, b);
            //Angular2LineDimension dim_insertAgl = new Angular2LineDimension(new Line(i4, i3), new Line(i4, i1), offset * 0.5, dimensionStyle);
            //dim_insertAgl.UserText = Math.Round(insertAngle * 180 / pi, 2) + "°";
            //dxf.AddEntity(dim_insertAgl);
            Angular2LineDimension dim_cutagl = new Angular2LineDimension(new Line(new Vector2(i4.X, i4.Y), new Vector2(i3.X, i3.Y)), new Line(new Vector2(i4.X, i4.Y), fun.Polar(new Vector2(i4.X, i4.Y), pi, 1)), offset * 0.4, dimensionStyle);
            dim_cutagl.UserText = Math.Round(cutagl * 180 / pi, 2) + "°";
            dxf.AddEntity(dim_cutagl);
            RadialDimension dim_repsilon = new RadialDimension(Pus.GetArcFromPline(minsert, 1), Pus.Degree(i3, i4) - 45, offset * 0.5, dimensionStyle);
            dim_repsilon.UserText = "rε=" + repsilon;
            dxf.AddEntity(dim_repsilon);
            //放倒(所有点)尚未平移到下方，因为只能绕着原点k所在轴旋转
            Vector3 rotate = new Vector3(-1, 0, 0);
            double rotateAgl = pi / 2;
            i4 = Pus.Rodrigue(rotate, 1, rotateAgl, i4);
            i3 = Pus.Rodrigue(rotate, 1, rotateAgl, i3);
            i2 = Pus.Rodrigue(rotate, 1, rotateAgl, i2);
            i1 = Pus.Rodrigue(rotate, 1, rotateAgl, i1);
            dt1 = Pus.Rodrigue(rotate, 1, rotateAgl, dt1);
            dt2 = Pus.Rodrigue(rotate, 1, rotateAgl, dt2);
            dt3 = Pus.Rodrigue(rotate, 1, rotateAgl, dt3);
            dt4 = Pus.Rodrigue(rotate, 1, rotateAgl, dt4);
            ii4 = Pus.Rodrigue(rotate, 1, rotateAgl, ii4);
            ii3 = Pus.Rodrigue(rotate, 1, rotateAgl, ii3);
            ii2 = Pus.Rodrigue(rotate, 1, rotateAgl, ii2);
            ii1 = Pus.Rodrigue(rotate, 1, rotateAgl, ii1);

            b1 = Pus.Rodrigue(rotate, 1, rotateAgl, b1);
            b2 = Pus.Rodrigue(rotate, 1, rotateAgl, b2);
            b3 = Pus.Rodrigue(rotate, 1, rotateAgl, b3);
            b4 = Pus.Rodrigue(rotate, 1, rotateAgl, b4);
            b5 = Pus.Rodrigue(rotate, 1, rotateAgl, b5);
            b6 = Pus.Rodrigue(rotate, 1, rotateAgl, b6);

            u1 = Pus.Rodrigue(rotate, 1, rotateAgl, u1);
            u2 = Pus.Rodrigue(rotate, 1, rotateAgl, u2);
            u3 = Pus.Rodrigue(rotate, 1, rotateAgl, u3);
            u3p = Pus.Rodrigue(rotate, 1, rotateAgl, u3p);
            u4 = Pus.Rodrigue(rotate, 1, rotateAgl, u4);

            //创建lambds
            rotate = new Vector3(Math.Cos(pi - cutagl + pi / 2), Math.Sin(pi - cutagl + pi / 2), k.Z);
            rotateAgl = -lambdas;
            i4 = Pus.Rodrigue(rotate, 1, rotateAgl, i4);
            i3 = Pus.Rodrigue(rotate, 1, rotateAgl, i3);
            i2 = Pus.Rodrigue(rotate, 1, rotateAgl, i2);
            i1 = Pus.Rodrigue(rotate, 1, rotateAgl, i1);
            ii4 = Pus.Rodrigue(rotate, 1, rotateAgl, ii4);
            ii3 = Pus.Rodrigue(rotate, 1, rotateAgl, ii3);
            ii2 = Pus.Rodrigue(rotate, 1, rotateAgl, ii2);
            ii1 = Pus.Rodrigue(rotate, 1, rotateAgl, ii1);
            dt1 = Pus.Rodrigue(rotate, 1, rotateAgl, dt1);
            dt2 = Pus.Rodrigue(rotate, 1, rotateAgl, dt2);
            dt3 = Pus.Rodrigue(rotate, 1, rotateAgl, dt3);
            dt4 = Pus.Rodrigue(rotate, 1, rotateAgl, dt4);

            //创建gamo
            double disi3_i4 = Vector3.Distance(i3, i4);
            rotate = (i3 - i4) / disi3_i4;
            rotateAgl = -gamao;
            i4 = Pus.Rodrigue(rotate, 1, rotateAgl, i4);
            i3 = Pus.Rodrigue(rotate, 1, rotateAgl, i3);
            i2 = Pus.Rodrigue(rotate, 1, rotateAgl, i2);
            i1 = Pus.Rodrigue(rotate, 1, rotateAgl, i1);
            ii4 = Pus.Rodrigue(rotate, 1, rotateAgl, ii4);
            ii3 = Pus.Rodrigue(rotate, 1, rotateAgl, ii3);
            ii2 = Pus.Rodrigue(rotate, 1, rotateAgl, ii2);
            ii1 = Pus.Rodrigue(rotate, 1, rotateAgl, ii1);
            dt1 = Pus.Rodrigue(rotate, 1, rotateAgl, dt1);
            dt2 = Pus.Rodrigue(rotate, 1, rotateAgl, dt2);
            dt3 = Pus.Rodrigue(rotate, 1, rotateAgl, dt3);
            dt4 = Pus.Rodrigue(rotate, 1, rotateAgl, dt4);

            //重新计算刀头的点
            Face3d face4dt = new Face3d(dt2, dt3, dt4);
            Vector3 v4dt = u2 - b2;
            dt2 = Pus.Inters(face4dt, new Line(u3p, u3p + v4dt));
            dt3 = Pus.Inters(face4dt, new Line(b3, b3 + v4dt));
            dt4 = Pus.Inters(face4dt, new Line(b4, b4 + v4dt));

            Face3d face4buttom = new Face3d(b1, b2, b3);
            b5 = Pus.Inters(face4buttom, new Line(i4, ii4));

            //平移所有点到下方
            Vector3 voff = new Vector3(0, -15 * kscale, 0);
            Vector3 mk = Pus.OffsetXY(voff, k);
            Vector3 mi4 = Pus.OffsetXY(voff, i4);
            Vector3 mi3 = Pus.OffsetXY(voff, i3);
            Vector3 mi2 = Pus.OffsetXY(voff, i2);
            Vector3 mi1 = Pus.OffsetXY(voff, i1);
            Vector3 mdt1 = Pus.OffsetXY(voff, dt1);
            Vector3 mdt2 = Pus.OffsetXY(voff, dt2);
            Vector3 mdt3 = Pus.OffsetXY(voff, dt3);
            Vector3 mdt4 = Pus.OffsetXY(voff, dt4);
            Vector3 mii4 = Pus.OffsetXY(voff, ii4);
            Vector3 mii3 = Pus.OffsetXY(voff, ii3);
            Vector3 mii2 = Pus.OffsetXY(voff, ii2);
            Vector3 mii1 = Pus.OffsetXY(voff, ii1);

            Vector3 mb1 = Pus.OffsetXY(voff, b1);
            Vector3 mb2 = Pus.OffsetXY(voff, b2);
            Vector3 mb3 = Pus.OffsetXY(voff, b3);
            Vector3 mb4 = Pus.OffsetXY(voff, b4);
            Vector3 mb5 = Pus.OffsetXY(voff, b5);
            Vector3 mb6 = Pus.OffsetXY(voff, b6);

            Vector3 mu1 = Pus.OffsetXY(voff, u1);
            Vector3 mu2 = Pus.OffsetXY(voff, u2);
            Vector3 mu3 = Pus.OffsetXY(voff, u3);
            Vector3 mu4 = Pus.OffsetXY(voff, u4);

            LwPolyline lshank = Pus.AddPointsToLwPolyLine(mb1, mu1, mu4, mb6);
            lshank.IsClosed = true;
            fun.PolyFill(dxf, lshank, lineWidth, contour);
            LwPolyline lshank_dt = Pus.AddPointsToLwPolyLine(mdt1, mu4);
            fun.PolyFill(dxf, lshank_dt, lineWidth, contour);

            LwPolyline lhead = Pus.AddPointsToLwPolyLine(mb6, mdt1, mi1, mii1, mii4, mb5);
            lhead.IsClosed = true;
            fun.PolyFill(dxf, lhead, lineWidth, contour);
            if (lambdas > 0)
            {
                LwPolyline lheadu = Pus.AddPointsToLwPolyLine(mi1, mdt1, mdt2, mdt3, mdt4, mi3);
                fun.PolyFill(dxf, lheadu, lineWidth, contour);

                LwPolyline linsertu = Pus.AddPointsToLwPolyLine(mi4, mi1, mi2, mi3);
                linsertu.IsClosed = true;
                fun.PolyFill(dxf, linsertu, lineWidth, cutting);
            }

            LwPolyline linsertf = Pus.AddPointsToLwPolyLine(mi4, mii4, mii1, mi1);
            linsertf.IsClosed = true;
            fun.PolyFill(dxf, linsertf, lineWidth, cutting);
            //m视图标注
            LinearDimension dim_h1 = new LinearDimension(new Line(new Vector2(mk.X, mk.Y), new Vector2(mb5.X, mb5.Y)), offset * 0.7, Pus.Degree(b1, u1), dimensionStyle);
            fun.dxflinedim(dxf, dim_h1, h1);
            LinearDimension dim_h2 = new LinearDimension(new Line(new Vector2(mu1.X, mu1.Y), new Vector2(mb1.X, mb1.Y)), offset, Pus.Degree(u1, b1), dimensionStyle);
            fun.dxflinedim(dxf, dim_h2, h2);
            if (gamao == 0)
                Pus.NeedleDim(dxf, new Line(new Vector2(mi3.X, mi3.Y), fun.Polar(new Vector2(mi3.X, mi3.Y), pi + pi / 180, 1)), new Line(new Vector2(mi2.X, mi2.Y), new Vector2(mi3.X, mi3.Y)), offset, "γo=0°", dimensionStyle);
            else
                Pus.NeedleDim(dxf, new Line(mi2, mi3), new Line(new Vector2(mi3.X, mi3.Y), fun.Polar(new Vector2(mi3.X, mi3.Y), pi, 1)), offset, "γo=" + Math.Round(gamao * 180 / pi, 2) + "°", dimensionStyle);
            //左视图
            //所有点移动到原点
            //立正
            rotate = new Vector3(1, 0, 0);
            rotateAgl = pi / 2;
            Vector3 zi4 = Pus.Rodrigue(rotate, 1, rotateAgl, i4);
            Vector3 zi3 = Pus.Rodrigue(rotate, 1, rotateAgl, i3);
            Vector3 zi2 = Pus.Rodrigue(rotate, 1, rotateAgl, i2);
            Vector3 zi1 = Pus.Rodrigue(rotate, 1, rotateAgl, i1);
            Vector3 zdt1 = Pus.Rodrigue(rotate, 1, rotateAgl, dt1);
            Vector3 zdt2 = Pus.Rodrigue(rotate, 1, rotateAgl, dt2);
            Vector3 zdt3 = Pus.Rodrigue(rotate, 1, rotateAgl, dt3);
            Vector3 zdt4 = Pus.Rodrigue(rotate, 1, rotateAgl, dt4);
            Vector3 zii4 = Pus.Rodrigue(rotate, 1, rotateAgl, ii4);
            Vector3 zii3 = Pus.Rodrigue(rotate, 1, rotateAgl, ii3);
            Vector3 zii2 = Pus.Rodrigue(rotate, 1, rotateAgl, ii2);
            Vector3 zii1 = Pus.Rodrigue(rotate, 1, rotateAgl, ii1);

            Vector3 zb1 = Pus.Rodrigue(rotate, 1, rotateAgl, b1);
            Vector3 zb2 = Pus.Rodrigue(rotate, 1, rotateAgl, b2);
            Vector3 zb3 = Pus.Rodrigue(rotate, 1, rotateAgl, b3);
            Vector3 zb4 = Pus.Rodrigue(rotate, 1, rotateAgl, b4);
            Vector3 zb5 = Pus.Rodrigue(rotate, 1, rotateAgl, b5);
            Vector3 zb6 = Pus.Rodrigue(rotate, 1, rotateAgl, b6);

            Vector3 zu1 = Pus.Rodrigue(rotate, 1, rotateAgl, u1);
            Vector3 zu2 = Pus.Rodrigue(rotate, 1, rotateAgl, u2);
            Vector3 zu3 = Pus.Rodrigue(rotate, 1, rotateAgl, u3);
            Vector3 zu4 = Pus.Rodrigue(rotate, 1, rotateAgl, u4);

            //绕y转，露出左面
            rotate = new Vector3(0, 1, 0);
            rotateAgl = pi / 2;
            zi4 = Pus.Rodrigue(rotate, 1, rotateAgl, zi4);
            zi3 = Pus.Rodrigue(rotate, 1, rotateAgl, zi3);
            zi2 = Pus.Rodrigue(rotate, 1, rotateAgl, zi2);
            zi1 = Pus.Rodrigue(rotate, 1, rotateAgl, zi1);
            zdt1 = Pus.Rodrigue(rotate, 1, rotateAgl, zdt1);
            zdt2 = Pus.Rodrigue(rotate, 1, rotateAgl, zdt2);
            zdt3 = Pus.Rodrigue(rotate, 1, rotateAgl, zdt3);
            zdt4 = Pus.Rodrigue(rotate, 1, rotateAgl, zdt4);
            zii4 = Pus.Rodrigue(rotate, 1, rotateAgl, zii4);
            zii3 = Pus.Rodrigue(rotate, 1, rotateAgl, zii3);
            zii2 = Pus.Rodrigue(rotate, 1, rotateAgl, zii2);
            zii1 = Pus.Rodrigue(rotate, 1, rotateAgl, zii1);

            zb1 = Pus.Rodrigue(rotate, 1, rotateAgl, zb1);
            zb2 = Pus.Rodrigue(rotate, 1, rotateAgl, zb2);
            zb3 = Pus.Rodrigue(rotate, 1, rotateAgl, zb3);
            zb4 = Pus.Rodrigue(rotate, 1, rotateAgl, zb4);
            zb5 = Pus.Rodrigue(rotate, 1, rotateAgl, zb5);
            zb6 = Pus.Rodrigue(rotate, 1, rotateAgl, zb6);

            zu1 = Pus.Rodrigue(rotate, 1, rotateAgl, zu1);
            zu2 = Pus.Rodrigue(rotate, 1, rotateAgl, zu2);
            zu3 = Pus.Rodrigue(rotate, 1, rotateAgl, zu3);
            zu4 = Pus.Rodrigue(rotate, 1, rotateAgl, zu4);

            //平移
            voff = new Vector3(-25 * kscale, 0, 0);
            zi4 = Pus.OffsetXY(voff, zi4);
            zi3 = Pus.OffsetXY(voff, zi3);
            zi2 = Pus.OffsetXY(voff, zi2);
            zi1 = Pus.OffsetXY(voff, zi1);
            zdt1 = Pus.OffsetXY(voff, zdt1);
            zdt2 = Pus.OffsetXY(voff, zdt2);
            zdt3 = Pus.OffsetXY(voff, zdt3);
            zdt4 = Pus.OffsetXY(voff, zdt4);
            zii4 = Pus.OffsetXY(voff, zii4);
            zii3 = Pus.OffsetXY(voff, zii3);
            zii2 = Pus.OffsetXY(voff, zii2);
            zii1 = Pus.OffsetXY(voff, zii1);

            zb1 = Pus.OffsetXY(voff, zb1);
            zb2 = Pus.OffsetXY(voff, zb2);
            zb3 = Pus.OffsetXY(voff, zb3);
            zb4 = Pus.OffsetXY(voff, zb4);
            zb5 = Pus.OffsetXY(voff, zb5);
            zb6 = Pus.OffsetXY(voff, zb6);

            zu1 = Pus.OffsetXY(voff, zu1);
            zu2 = Pus.OffsetXY(voff, zu2);
            zu3 = Pus.OffsetXY(voff, zu3);
            zu4 = Pus.OffsetXY(voff, zu4);

            //左视图绘制
            LwPolyline zshank = Pus.AddPointsToLwPolyLine(zii4, zb5, zb4, zb3, zdt3, zdt4, zi3);
            fun.PolyFill(dxf, zshank, lineWidth, contour);
            LwPolyline zshank2 = Pus.AddPointsToLwPolyLine(zb4, zdt4);
            fun.PolyFill(dxf, zshank2, lineWidth, contour);
            if (gamao > 0)
            {
                LwPolyline zshank1 = Pus.AddPointsToLwPolyLine(zdt3, zdt2, zdt1, zi1);
                fun.PolyFill(dxf, zshank1, lineWidth, contour);

                LwPolyline zinsert = Pus.AddPointsToLwPolyLine(zi4, zi1, zi2, zi3);
                zinsert.IsClosed = true;
                fun.PolyFill(dxf, zinsert, lineWidth, cutting);
            }

            LwPolyline zlen1 = Pus.AddPointsToLwPolyLine(zi3, zii3, zii4, zi4);
            zlen1.IsClosed = true;
            fun.PolyFill(dxf, zlen1, lineWidth, cutting);
            //左视图标注
            //刃倾角
            if (lambdas == 0)
                Pus.NeedleDim(dxf, new Line(new Vector2(zi4.X, zi4.Y), fun.Polar(new Vector2(zi4.X, zi4.Y), pi / 2 + pi / 180, 1)), new Line(zi3, zi4), offset, "λs=0°", dimensionStyle);
            else
                Pus.NeedleDim(dxf, new Line(zi3, zi4), new Line(new Vector2(zi4.X, zi4.Y), fun.Polar(new Vector2(zi4.X, zi4.Y), pi / 2, 1)), offset, "λs=" + Math.Round(lambdas * 180 / pi, 2) + "°", dimensionStyle);
            LinearDimension dim_s = new LinearDimension(new Line(zi4, zii4), offset * 0.7, Pus.Degree(zi4, zi3) + 90, dimensionStyle);
            fun.dxflinedim(dxf, dim_s, s);
            //后角
            if (alphan == 0)
                Pus.NeedleDim(dxf, new Line(new Vector2(zi4.X, zi4.Y), fun.Polar(new Vector2(zi4.X, zi4.Y), Pus.Degree(zi4, zi3) * pi / 180 + pi / 2 + pi / 180, 1)), new Line(zii4, zi4), offset * 0.5, "αn=0°", dimensionStyle);
            else
                Pus.NeedleDim(dxf, new Line(new Vector2(zi4.X, zi4.Y), fun.Polar(new Vector2(zi4.X, zi4.Y), Pus.Degree(zi4, zi3) * pi / 180 + pi / 2, 1)), new Line(zii4, zi4), offset * 0.5, "αn=" + Math.Round(alphan * 180 / pi, 2) + "°", dimensionStyle);
            //图框
            if (Convert.ToDouble(data["isframe"]) == 1)
            {
                Vector2 c4c = new Vector2((b2.X + zb3.X) / 2, (b2.Y + mu1.Y) / 2);
                Dictionary<string, Vector2> positions = Frame.frameA3X(dxf, new Vector2(c4c.X - 420 / 2, c4c.Y + 297 / 2), new Dictionary<string, object>());
                fun.writetextofC(dxf, kscale + ":1", positions["比例"], 3.5, 0, 0.6, 3);
            }

            dxf.DrawingVariables.AcadVer = DxfVersion.AutoCad2007;
            dxf.Save(path);
        }
        public static void StyleL_InsertW(Dictionary<string, Object> data)
        {
            DxfDocument dxf = new DxfDocument();
            Layer contour = new Layer("contour") { Color = AciColor.Cyan };    //1,轮廓层
            Layer cutting = new Layer("cutting") { Color = AciColor.Red };    //切削层
            cutting.Lineweight = Lineweight.W200;

            string path = Convert.ToString(data["path"]);
            //参数名称取自ISO 5610
            double b = 8;
            double l1 = 100;
            double l2 = 25;
            double f = 10;
            double l3 = 4.35;
            double h2 = 8;
            double h1 = 8;
            double s = 2.38;
            double insertAngle = 80 * pi / 180;
            double alphan = 0 * pi / 180;
            double cutagl = 95 * pi / 180;
            double lambdas = 0;
            double gamao = 0;
            double repsilon = 0;
            #region
            try
            {
                if (data["re"] != null)
                    repsilon = Convert.ToDouble(data["re"]);
                if (repsilon <= 0)
                    repsilon = 0.01;
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["lams"] != null)
                    lambdas = Math.Abs(Convert.ToDouble(data["lams"]) * pi / 180);
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["gamo"] != null)
                    gamao = Math.Abs(Convert.ToDouble(data["gamo"]) * pi / 180);
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["b"] != null)
                    b = Convert.ToDouble(data["b"]);
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["s"] != null)
                    s = Convert.ToDouble(data["s"]);
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["lf"] != null)
                    l1 = Convert.ToDouble(data["lf"]);
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["lh"] != null)
                    l2 = Convert.ToDouble(data["lh"]);
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["wf"] != null)
                    f = Convert.ToDouble(data["wf"]);
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["h"] != null)
                    h2 = Convert.ToDouble(data["h"]);
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["hf"] != null)
                    h1 = Convert.ToDouble(data["hf"]);
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["epsr"] != null)
                    insertAngle = Convert.ToDouble(data["epsr"]) * pi / 180;
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["kapr"] != null)
                    cutagl = Convert.ToDouble(data["kapr"]) * pi / 180;
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["an"] != null)
                    alphan = Convert.ToDouble(data["an"]) * pi / 180;
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["ic"] != null)
                    l3 = Pus.GetLByHIC(Convert.ToDouble(data["ic"]));
            }
            catch (KeyNotFoundException) { }
            #endregion
            //线性变换
            Vector2 zero = new Vector2(0, 0);
            double kscale = 1;
            if (l1 >= 120)
                kscale = 1;
            else
                kscale = 1.5;
            double lineWidth = 1;
            //k点位置恒定
            Vector3 k = new Vector3(0, 0, 0);
            Vector3 b2 = new Vector3(k.X + l1, k.Y + f, k.Z - h1);
            Vector3 b1 = new Vector3(b2.X, b2.Y - b, b2.Z);
            Vector3 b6 = new Vector3(k.X + l2, b1.Y, b1.Z);

            //刀杆顶面
            Vector3 u1 = new Vector3(b1.X, b1.Y, b1.Z + h2);
            Vector3 u2 = new Vector3(b2.X, b2.Y, b2.Z + h2);
            Vector3 u3 = new Vector3(b6.X, b2.Y, b2.Z + h2);
            Vector3 u4 = new Vector3(b6.X, b6.Y, b6.Z + h2);

            //前角与刃倾角都为0时刀尖点与k的关系,"纵向进给，主偏角大于90°k点与i4的关系"
            Vector2 cen = fun.Polar(new Vector2(k.X, k.Y), pi / 4, repsilon / Math.Sin(pi / 4));
            Vector2 twoi6 = fun.Polar(cen, 2 * pi - cutagl - insertAngle / 2, repsilon / Math.Sin(insertAngle / 2));
            Vector2[] twois = Pus.Hexagonal(twoi6, l3, insertAngle, cutagl, false);
            Vector2 twoi1 = twois[1];
            Vector2 twoi2 = twois[2];
            Vector2 twoi3 = twois[3];
            Vector2 twoi4 = twois[4];
            Vector2 twoi5 = twois[5];
            double theoffset = Math.Tan(alphan) * s;
            Vector2[] twoiis = Pus.OffsetPoints(theoffset, twois);
            Vector2 twoii6 = twoiis[0];
            Vector2 twoii3 = twoiis[3];
            Vector2 twoii1 = twoiis[1];
            Vector2 twoii2 = twoiis[2];
            Vector2 twoii4 = twoiis[4];
            Vector2 twoii5 = twoiis[5];

            //刀头面
            Vector3 i6 = new Vector3(twoi6.X, twoi6.Y, k.Z);
            Vector3 i5 = new Vector3(twoi5.X, twoi5.Y, k.Z);
            Vector3 i4 = new Vector3(twoi4.X, twoi4.Y, k.Z);
            Vector3 i3 = new Vector3(twoi3.X, twoi3.Y, k.Z);
            Vector3 i2 = new Vector3(twoi2.X, twoi2.Y, k.Z);
            Vector3 i1 = new Vector3(twoi1.X, twoi1.Y, k.Z);
            Vector3 dt1 = u4;
            Vector3 dt2 = u3;
            Vector2 xx = Pus.IntersOnP(i5, i4, u2, u3);
            Vector3 dt3 = new Vector3(xx.X, xx.Y, u3.Z);

            Vector3 ii6 = new Vector3(twoii6.X, twoii6.Y, k.Z - s);
            Vector3 ii5 = new Vector3(twoii5.X, twoii5.Y, k.Z - s);
            Vector3 ii4 = new Vector3(twoii4.X, twoii4.Y, k.Z - s);
            Vector3 ii3 = new Vector3(twoii3.X, twoii3.Y, k.Z - s);
            Vector3 ii1 = new Vector3(twoii1.X, twoii1.Y, k.Z - s);
            Vector3 ii2 = new Vector3(twoii2.X, twoii2.Y, k.Z - s);


            Vector3 b5 = new Vector3(ii6.X, ii6.Y, b1.Z);
            Vector3 b3 = new Vector3(dt3.X, dt3.Y, b1.Z);
            Vector3 bi1 = new Vector3(ii1.X, ii1.Y, b1.Z);
            Vector3 bi2 = new Vector3(ii2.X, ii2.Y, b1.Z);
            Vector3 bi5 = new Vector3(ii5.X, ii5.Y, b1.Z);

            i6 = Pus.LinearTrans(kscale, i6);
            i5 = Pus.LinearTrans(kscale, i5);
            i4 = Pus.LinearTrans(kscale, i4);
            i3 = Pus.LinearTrans(kscale, i3);
            i2 = Pus.LinearTrans(kscale, i2);
            i1 = Pus.LinearTrans(kscale, i1);
            dt1 = Pus.LinearTrans(kscale, dt1);
            dt2 = Pus.LinearTrans(kscale, dt2);
            dt3 = Pus.LinearTrans(kscale, dt3);
            ii6 = Pus.LinearTrans(kscale, ii6);
            ii5 = Pus.LinearTrans(kscale, ii5);
            ii4 = Pus.LinearTrans(kscale, ii4);
            ii3 = Pus.LinearTrans(kscale, ii3);
            ii2 = Pus.LinearTrans(kscale, ii2);
            ii1 = Pus.LinearTrans(kscale, ii1);

            b1 = Pus.LinearTrans(kscale, b1);
            b2 = Pus.LinearTrans(kscale, b2);
            b3 = Pus.LinearTrans(kscale, b3);
            b5 = Pus.LinearTrans(kscale, b5);
            b6 = Pus.LinearTrans(kscale, b6);
            bi1 = Pus.LinearTrans(kscale, bi1);
            bi2 = Pus.LinearTrans(kscale, bi2);
            bi5 = Pus.LinearTrans(kscale, bi5);

            u1 = Pus.LinearTrans(kscale, u1);
            u2 = Pus.LinearTrans(kscale, u2);
            u3 = Pus.LinearTrans(kscale, u3);
            u4 = Pus.LinearTrans(kscale, u4);

            //主视图
            LwPolyline mshank = Pus.AddPointsToLwPolyLine(u1, u2, u3, u4);
            mshank.IsClosed = true;
            fun.PolyFill(dxf, mshank, lineWidth, contour);

            LwPolyline minsert = Pus.AddPointsToLwPolyLine(i6, i1, i2, i3, i4, i5);
            minsert.IsClosed = true;
            Pus.AglToArc(minsert, repsilon);
            Vector2 vertex4 = minsert.Vertexes[4].Position;
            Vector2 vertex9 = minsert.Vertexes[9].Position;

            LwPolyline mhead = Pus.AddPointsToLwPolyLine(new Vector3(vertex4.X, vertex4.Y, 0.0), dt1, dt2, dt3, new Vector3(vertex9.X, vertex9.Y, 0.0));
            fun.PolyFill(dxf, mhead, lineWidth, contour);

            fun.PolyFill(dxf, minsert, lineWidth, cutting);
            //主视图标注
            DimensionStyle dimensionStyle = new DimensionStyle("mystyle");
            dimensionStyle.ArrowSize = kscale * 1.7;
            dimensionStyle.DimArrow1 = DimensionArrowhead.Closedfilled;
            dimensionStyle.DimArrow2 = DimensionArrowhead.Closedfilled;
            dimensionStyle.TextHeight = kscale * 2;
            dimensionStyle.TextOffset = kscale / 2;
            double offset = 7 * kscale;
            LinearDimension dim_f = new LinearDimension(new Line(new Vector2(k.X, k.Y), new Vector2(b3.X, b3.Y)), offset * 1.5, Pus.Degree(b1, b2), dimensionStyle);
            fun.dxflinedim(dxf, dim_f, f);
            LinearDimension dim_l1 = new LinearDimension(new Line(new Vector2(k.X, k.Y), new Vector2(b1.X, b1.Y)), offset, Pus.Degree(new Vector2(b1.X, b1.Y), new Vector2(b6.X, b6.Y)), dimensionStyle);
            fun.dxflinedim(dxf, dim_l1, l1);
            LinearDimension dim_l2 = new LinearDimension(new Line(new Vector2(k.X, k.Y), new Vector2(u4.X, u4.Y)), offset * 0.7, Pus.Degree(new Vector2(u1.X, u1.Y), new Vector2(u4.X, u4.Y)), dimensionStyle);
            fun.dxflinedim(dxf, dim_l2, l2);
            LinearDimension dim_l3 = new LinearDimension(new Line(new Vector2(i3.X, i3.Y), new Vector2(i4.X, i4.Y)), offset * 0.6, Pus.Degree(new Vector2(i4.X, i4.Y), new Vector2(i3.X, i3.Y)), dimensionStyle);
            fun.dxflinedim(dxf, dim_l3, Math.Round(l3, 2));
            LinearDimension dim_b = new LinearDimension(new Line(new Vector2(u1.X, u1.Y), new Vector2(u2.X, u2.Y)), offset, Pus.Degree(new Vector2(u2.X, u2.Y), new Vector2(u1.X, u1.Y)), dimensionStyle);
            fun.dxflinedim(dxf, dim_b, b);
            //Angular2LineDimension dim_insertAgl = new Angular2LineDimension(new Line(i6, i5), new Line(i6, i1), offset * 0.5, dimensionStyle);
            //dim_insertAgl.UserText = Math.Round(insertAngle * 180 / pi, 2) + "°";
            //dxf.AddEntity(dim_insertAgl);
            Angular2LineDimension dim_cutagl = new Angular2LineDimension(new Line(new Vector2(i6.X, i6.Y), new Vector2(i5.X, i5.Y)), new Line(new Vector2(i6.X, i6.Y), fun.Polar(new Vector2(i6.X, i6.Y), pi, 1)), offset * 0.5, dimensionStyle);
            dim_cutagl.UserText = Math.Round(cutagl * 180 / pi, 2) + "°";
            dxf.AddEntity(dim_cutagl);
            RadialDimension dim_repsilon = new RadialDimension(Pus.GetArcFromPline(minsert, 1), Pus.Degree(i5, i6) - 45, offset * 0.5, dimensionStyle);
            dim_repsilon.UserText = "rε=" + repsilon;
            dxf.AddEntity(dim_repsilon);
            //放倒(所有点)尚未平移到下方，因为只能绕着原点k所在轴旋转
            Vector3 rotate = new Vector3(-1, 0, 0);
            double rotateAgl = pi / 2;
            i6 = Pus.Rodrigue(rotate, 1, rotateAgl, i6);
            i5 = Pus.Rodrigue(rotate, 1, rotateAgl, i5);
            i4 = Pus.Rodrigue(rotate, 1, rotateAgl, i4);
            i3 = Pus.Rodrigue(rotate, 1, rotateAgl, i3);
            i2 = Pus.Rodrigue(rotate, 1, rotateAgl, i2);
            i1 = Pus.Rodrigue(rotate, 1, rotateAgl, i1);
            dt1 = Pus.Rodrigue(rotate, 1, rotateAgl, dt1);
            dt2 = Pus.Rodrigue(rotate, 1, rotateAgl, dt2);
            dt3 = Pus.Rodrigue(rotate, 1, rotateAgl, dt3);
            ii6 = Pus.Rodrigue(rotate, 1, rotateAgl, ii6);
            ii5 = Pus.Rodrigue(rotate, 1, rotateAgl, ii5);
            ii4 = Pus.Rodrigue(rotate, 1, rotateAgl, ii4);
            ii3 = Pus.Rodrigue(rotate, 1, rotateAgl, ii3);
            ii2 = Pus.Rodrigue(rotate, 1, rotateAgl, ii2);
            ii1 = Pus.Rodrigue(rotate, 1, rotateAgl, ii1);

            b1 = Pus.Rodrigue(rotate, 1, rotateAgl, b1);
            b2 = Pus.Rodrigue(rotate, 1, rotateAgl, b2);
            b3 = Pus.Rodrigue(rotate, 1, rotateAgl, b3);
            b5 = Pus.Rodrigue(rotate, 1, rotateAgl, b5);
            b6 = Pus.Rodrigue(rotate, 1, rotateAgl, b6);
            bi1 = Pus.Rodrigue(rotate, 1, rotateAgl, bi1);
            bi2 = Pus.Rodrigue(rotate, 1, rotateAgl, bi2);
            bi5 = Pus.Rodrigue(rotate, 1, rotateAgl, bi5);

            u1 = Pus.Rodrigue(rotate, 1, rotateAgl, u1);
            u2 = Pus.Rodrigue(rotate, 1, rotateAgl, u2);
            u3 = Pus.Rodrigue(rotate, 1, rotateAgl, u3);
            u4 = Pus.Rodrigue(rotate, 1, rotateAgl, u4);

            //创建lambds
            rotate = new Vector3(Math.Cos(pi - cutagl + pi / 2), Math.Sin(pi - cutagl + pi / 2), k.Z);
            rotateAgl = -lambdas;
            i6 = Pus.Rodrigue(rotate, 1, rotateAgl, i6);
            i5 = Pus.Rodrigue(rotate, 1, rotateAgl, i5);
            i4 = Pus.Rodrigue(rotate, 1, rotateAgl, i4);
            i3 = Pus.Rodrigue(rotate, 1, rotateAgl, i3);
            i2 = Pus.Rodrigue(rotate, 1, rotateAgl, i2);
            i1 = Pus.Rodrigue(rotate, 1, rotateAgl, i1);
            ii6 = Pus.Rodrigue(rotate, 1, rotateAgl, ii6);
            ii5 = Pus.Rodrigue(rotate, 1, rotateAgl, ii5);
            ii4 = Pus.Rodrigue(rotate, 1, rotateAgl, ii4);
            ii3 = Pus.Rodrigue(rotate, 1, rotateAgl, ii3);
            ii2 = Pus.Rodrigue(rotate, 1, rotateAgl, ii2);
            ii1 = Pus.Rodrigue(rotate, 1, rotateAgl, ii1);
            dt1 = Pus.Rodrigue(rotate, 1, rotateAgl, dt1);
            dt2 = Pus.Rodrigue(rotate, 1, rotateAgl, dt2);
            dt3 = Pus.Rodrigue(rotate, 1, rotateAgl, dt3);

            //创建gamo
            double disi5_i6 = Vector3.Distance(i5, i6);
            rotate = (i5 - i6) / disi5_i6;
            rotateAgl = -gamao;
            i6 = Pus.Rodrigue(rotate, 1, rotateAgl, i6);
            i5 = Pus.Rodrigue(rotate, 1, rotateAgl, i5);
            i4 = Pus.Rodrigue(rotate, 1, rotateAgl, i4);
            i3 = Pus.Rodrigue(rotate, 1, rotateAgl, i3);
            i2 = Pus.Rodrigue(rotate, 1, rotateAgl, i2);
            i1 = Pus.Rodrigue(rotate, 1, rotateAgl, i1);
            ii6 = Pus.Rodrigue(rotate, 1, rotateAgl, ii6);
            ii5 = Pus.Rodrigue(rotate, 1, rotateAgl, ii5);
            ii4 = Pus.Rodrigue(rotate, 1, rotateAgl, ii4);
            ii3 = Pus.Rodrigue(rotate, 1, rotateAgl, ii3);
            ii2 = Pus.Rodrigue(rotate, 1, rotateAgl, ii2);
            ii1 = Pus.Rodrigue(rotate, 1, rotateAgl, ii1);
            dt1 = Pus.Rodrigue(rotate, 1, rotateAgl, dt1);
            dt2 = Pus.Rodrigue(rotate, 1, rotateAgl, dt2);
            dt3 = Pus.Rodrigue(rotate, 1, rotateAgl, dt3);

            //重新计算刀头的点
            Face3d face4dt = new Face3d(dt2, dt3, dt1);
            Vector3 v4dt = u2 - b2;
            Vector3 u3p = new Vector3(u3.X - 1, u3.Y, u3.Z);
            dt2 = Pus.Inters(face4dt, new Line(u3p, u3p + v4dt));
            dt3 = Pus.Inters(face4dt, new Line(b3, b3 + v4dt));
            //
            Face3d face4b = new Face3d(b1, b2, b3);
            Vector3 v4b = b1 - u1;
            b5 = Pus.Inters(face4b, new Line(ii6, ii6 + v4b));
            bi1 = Pus.Inters(face4b, new Line(ii1, ii1 + v4b));
            bi2 = Pus.Inters(face4b, new Line(ii2, ii2 + v4b));
            bi5 = Pus.Inters(face4b, new Line(ii5, ii5 + v4b));

            //平移所有点到下方
            Vector3 voff = new Vector3(0, -20 * kscale, 0);
            Vector3 mk = Pus.OffsetXY(voff, k);
            Vector3 mi6 = Pus.OffsetXY(voff, i6);
            Vector3 mi5 = Pus.OffsetXY(voff, i5);
            Vector3 mi4 = Pus.OffsetXY(voff, i4);
            Vector3 mi3 = Pus.OffsetXY(voff, i3);
            Vector3 mi2 = Pus.OffsetXY(voff, i2);
            Vector3 mi1 = Pus.OffsetXY(voff, i1);
            Vector3 mdt1 = Pus.OffsetXY(voff, dt1);
            Vector3 mdt2 = Pus.OffsetXY(voff, dt2);
            Vector3 mdt3 = Pus.OffsetXY(voff, dt3);
            Vector3 mii6 = Pus.OffsetXY(voff, ii6);
            Vector3 mii5 = Pus.OffsetXY(voff, ii5);
            Vector3 mii4 = Pus.OffsetXY(voff, ii4);
            Vector3 mii3 = Pus.OffsetXY(voff, ii3);
            Vector3 mii2 = Pus.OffsetXY(voff, ii2);
            Vector3 mii1 = Pus.OffsetXY(voff, ii1);

            Vector3 mb1 = Pus.OffsetXY(voff, b1);
            Vector3 mb2 = Pus.OffsetXY(voff, b2);
            Vector3 mb3 = Pus.OffsetXY(voff, b3);
            Vector3 mb5 = Pus.OffsetXY(voff, b5);
            Vector3 mb6 = Pus.OffsetXY(voff, b6);
            Vector3 mbi1 = Pus.OffsetXY(voff, bi1);
            Vector3 mbi2 = Pus.OffsetXY(voff, bi2);
            Vector3 mbi5 = Pus.OffsetXY(voff, bi5);

            Vector3 mu1 = Pus.OffsetXY(voff, u1);
            Vector3 mu2 = Pus.OffsetXY(voff, u2);
            Vector3 mu3 = Pus.OffsetXY(voff, u3);
            Vector3 mu4 = Pus.OffsetXY(voff, u4);
            //lowwersview
            LwPolyline lshank = Pus.AddPointsToLwPolyLine(mb1, mu1, mu4, mb6);
            lshank.IsClosed = true;
            fun.PolyFill(dxf, lshank, lineWidth, contour);
            LwPolyline lshank_dt = Pus.AddPointsToLwPolyLine(mdt1, mu4);
            fun.PolyFill(dxf, lshank_dt, lineWidth, contour);

            LwPolyline lhead = Pus.AddPointsToLwPolyLine(mb6, mdt1, mi2, mii2, mii1, mii6, mb5);
            lhead.IsClosed = true;
            fun.PolyFill(dxf, lhead, lineWidth, contour);
            if (lambdas > 0)
            {
                LwPolyline lheadu = Pus.AddPointsToLwPolyLine(mdt1, mdt2, mdt3, mi4);
                fun.PolyFill(dxf, lheadu, lineWidth, contour);
            }
            LwPolyline lheadf1 = Pus.AddPointsToLwPolyLine(mii1, mbi1);
            fun.PolyFill(dxf, lheadf1, lineWidth, contour);
            LwPolyline lheadf2 = Pus.AddPointsToLwPolyLine(mii2, mbi2);
            fun.PolyFill(dxf, lheadf2, lineWidth, contour);

            if (lambdas > 0)
            {
                LwPolyline linsertu = Pus.AddPointsToLwPolyLine(mi6, mi1, mi2, mi3, mi4, mi5);
                linsertu.IsClosed = true;
                fun.PolyFill(dxf, linsertu, lineWidth, cutting);
            }
            LwPolyline linsertf = Pus.AddPointsToLwPolyLine(mi6, mii6, mii1, mii2, mi2, mi1);
            linsertf.IsClosed = true;
            fun.PolyFill(dxf, linsertf, lineWidth, cutting);
            LwPolyline llen1 = Pus.AddPointsToLwPolyLine(mii1, mi1);
            fun.PolyFill(dxf, llen1, lineWidth, cutting);
            //m视图标注
            LinearDimension dim_h1 = new LinearDimension(new Line(new Vector2(mk.X, mk.Y), new Vector2(mb5.X, mb5.Y)), offset * 0.7, Pus.Degree(mb1, mu1), dimensionStyle);
            fun.dxflinedim(dxf, dim_h1, h1);
            LinearDimension dim_h2 = new LinearDimension(new Line(new Vector2(mu1.X, mu1.Y), new Vector2(mb1.X, mb1.Y)), offset, Pus.Degree(mu1, mb1), dimensionStyle);
            fun.dxflinedim(dxf, dim_h2, h2);
            if (gamao == 0)
                Pus.NeedleDim(dxf, new Line(new Vector2(mi6.X, mi6.Y), fun.Polar(new Vector2(mi6.X, mi6.Y), pi + pi / 180, 1)), new Line(mi1, mi6), offset, "γo=0°", dimensionStyle);
            else
                Pus.NeedleDim(dxf, new Line(mi6, mi1), new Line(new Vector2(mi6.X, mi6.Y), fun.Polar(new Vector2(mi6.X, mi6.Y), pi, 1)), offset, "γo=" + Math.Round(gamao * 180 / pi, 2) + "°", dimensionStyle);
            //左视图
            //立正
            rotate = new Vector3(1, 0, 0);
            rotateAgl = pi / 2;
            Vector3 zi6 = Pus.Rodrigue(rotate, 1, rotateAgl, i6);
            Vector3 zi5 = Pus.Rodrigue(rotate, 1, rotateAgl, i5);
            Vector3 zi4 = Pus.Rodrigue(rotate, 1, rotateAgl, i4);
            Vector3 zi3 = Pus.Rodrigue(rotate, 1, rotateAgl, i3);
            Vector3 zi2 = Pus.Rodrigue(rotate, 1, rotateAgl, i2);
            Vector3 zi1 = Pus.Rodrigue(rotate, 1, rotateAgl, i1);
            Vector3 zdt1 = Pus.Rodrigue(rotate, 1, rotateAgl, dt1);
            Vector3 zdt2 = Pus.Rodrigue(rotate, 1, rotateAgl, dt2);
            Vector3 zdt3 = Pus.Rodrigue(rotate, 1, rotateAgl, dt3);
            Vector3 zii6 = Pus.Rodrigue(rotate, 1, rotateAgl, ii6);
            Vector3 zii5 = Pus.Rodrigue(rotate, 1, rotateAgl, ii5);
            Vector3 zii4 = Pus.Rodrigue(rotate, 1, rotateAgl, ii4);
            Vector3 zii3 = Pus.Rodrigue(rotate, 1, rotateAgl, ii3);
            Vector3 zii2 = Pus.Rodrigue(rotate, 1, rotateAgl, ii2);
            Vector3 zii1 = Pus.Rodrigue(rotate, 1, rotateAgl, ii1);

            Vector3 zb1 = Pus.Rodrigue(rotate, 1, rotateAgl, b1);
            Vector3 zb2 = Pus.Rodrigue(rotate, 1, rotateAgl, b2);
            Vector3 zb3 = Pus.Rodrigue(rotate, 1, rotateAgl, b3);
            Vector3 zb5 = Pus.Rodrigue(rotate, 1, rotateAgl, b5);
            Vector3 zb6 = Pus.Rodrigue(rotate, 1, rotateAgl, b6);
            Vector3 zbi1 = Pus.Rodrigue(rotate, 1, rotateAgl, bi1);
            Vector3 zbi2 = Pus.Rodrigue(rotate, 1, rotateAgl, bi2);
            Vector3 zbi5 = Pus.Rodrigue(rotate, 1, rotateAgl, bi5);

            Vector3 zu1 = Pus.Rodrigue(rotate, 1, rotateAgl, u1);
            Vector3 zu2 = Pus.Rodrigue(rotate, 1, rotateAgl, u2);
            Vector3 zu3 = Pus.Rodrigue(rotate, 1, rotateAgl, u3);
            Vector3 zu4 = Pus.Rodrigue(rotate, 1, rotateAgl, u4);

            //绕y转，露出左面
            rotate = new Vector3(0, 1, 0);
            rotateAgl = pi / 2;
            zi6 = Pus.Rodrigue(rotate, 1, rotateAgl, zi6);
            zi5 = Pus.Rodrigue(rotate, 1, rotateAgl, zi5);
            zi4 = Pus.Rodrigue(rotate, 1, rotateAgl, zi4);
            zi3 = Pus.Rodrigue(rotate, 1, rotateAgl, zi3);
            zi2 = Pus.Rodrigue(rotate, 1, rotateAgl, zi2);
            zi1 = Pus.Rodrigue(rotate, 1, rotateAgl, zi1);
            zdt1 = Pus.Rodrigue(rotate, 1, rotateAgl, zdt1);
            zdt2 = Pus.Rodrigue(rotate, 1, rotateAgl, zdt2);
            zdt3 = Pus.Rodrigue(rotate, 1, rotateAgl, zdt3); ;
            zii6 = Pus.Rodrigue(rotate, 1, rotateAgl, zii6);
            zii5 = Pus.Rodrigue(rotate, 1, rotateAgl, zii5);
            zii4 = Pus.Rodrigue(rotate, 1, rotateAgl, zii4);
            zii3 = Pus.Rodrigue(rotate, 1, rotateAgl, zii3);
            zii2 = Pus.Rodrigue(rotate, 1, rotateAgl, zii2);
            zii1 = Pus.Rodrigue(rotate, 1, rotateAgl, zii1);

            zb1 = Pus.Rodrigue(rotate, 1, rotateAgl, zb1);
            zb2 = Pus.Rodrigue(rotate, 1, rotateAgl, zb2);
            zb3 = Pus.Rodrigue(rotate, 1, rotateAgl, zb3);
            zb5 = Pus.Rodrigue(rotate, 1, rotateAgl, zb5);
            zb6 = Pus.Rodrigue(rotate, 1, rotateAgl, zb6);
            zbi1 = Pus.Rodrigue(rotate, 1, rotateAgl, zbi1);
            zbi2 = Pus.Rodrigue(rotate, 1, rotateAgl, zbi2);
            zbi5 = Pus.Rodrigue(rotate, 1, rotateAgl, zbi5);

            zu1 = Pus.Rodrigue(rotate, 1, rotateAgl, zu1);
            zu2 = Pus.Rodrigue(rotate, 1, rotateAgl, zu2);
            zu3 = Pus.Rodrigue(rotate, 1, rotateAgl, zu3);
            zu4 = Pus.Rodrigue(rotate, 1, rotateAgl, zu4);

            //平移
            voff = new Vector3(-25 * kscale, 0, 0);
            zi6 = Pus.OffsetXY(voff, zi6);
            zi5 = Pus.OffsetXY(voff, zi5);
            zi4 = Pus.OffsetXY(voff, zi4);
            zi3 = Pus.OffsetXY(voff, zi3);
            zi2 = Pus.OffsetXY(voff, zi2);
            zi1 = Pus.OffsetXY(voff, zi1);
            zdt1 = Pus.OffsetXY(voff, zdt1);
            zdt2 = Pus.OffsetXY(voff, zdt2);
            zdt3 = Pus.OffsetXY(voff, zdt3);
            zii6 = Pus.OffsetXY(voff, zii6);
            zii5 = Pus.OffsetXY(voff, zii5);
            zii4 = Pus.OffsetXY(voff, zii4);
            zii3 = Pus.OffsetXY(voff, zii3);
            zii2 = Pus.OffsetXY(voff, zii2);
            zii1 = Pus.OffsetXY(voff, zii1);

            zb1 = Pus.OffsetXY(voff, zb1);
            zb2 = Pus.OffsetXY(voff, zb2);
            zb3 = Pus.OffsetXY(voff, zb3);
            zb5 = Pus.OffsetXY(voff, zb5);
            zb6 = Pus.OffsetXY(voff, zb6);
            zbi1 = Pus.OffsetXY(voff, zbi1);
            zbi2 = Pus.OffsetXY(voff, zbi2);
            zbi5 = Pus.OffsetXY(voff, zbi5);

            zu1 = Pus.OffsetXY(voff, zu1);
            zu2 = Pus.OffsetXY(voff, zu2);
            zu3 = Pus.OffsetXY(voff, zu3);
            zu4 = Pus.OffsetXY(voff, zu4);

            //左视图绘制
            LwPolyline zshank = Pus.AddPointsToLwPolyLine(zii6, zb5, zbi5, zb3, zdt3, zi4);
            fun.PolyFill(dxf, zshank, lineWidth, contour);
            LwPolyline zshankf = Pus.AddPointsToLwPolyLine(zbi5, zii5);
            fun.PolyFill(dxf, zshankf, lineWidth, contour);

            if (gamao > 0)
            {
                LwPolyline zshank1 = Pus.AddPointsToLwPolyLine(zdt3, zdt2, zdt1, zi2);
                fun.PolyFill(dxf, zshank1, lineWidth, contour);

                LwPolyline zinsert = Pus.AddPointsToLwPolyLine(zi6, zi1, zi2, zi3, zi4, zi5);
                zinsert.IsClosed = true;
                fun.PolyFill(dxf, zinsert, lineWidth, cutting);
            }

            LwPolyline zinsertf = Pus.AddPointsToLwPolyLine(zii5, zi5);
            fun.PolyFill(dxf, zinsertf, lineWidth, cutting);

            LwPolyline zlen1 = Pus.AddPointsToLwPolyLine(zi4, zii4, zii5, zii6, zi6, zi5);
            zlen1.IsClosed = true;
            fun.PolyFill(dxf, zlen1, lineWidth, cutting);
            //左视图标注
            //刃倾角
            if (lambdas == 0)
                Pus.NeedleDim(dxf, new Line(new Vector2(zi6.X, zi6.Y), fun.Polar(new Vector2(zi6.X, zi6.Y), pi / 2 + pi / 180, 1)), new Line(zi5, zi6), offset, "λs=0°", dimensionStyle);
            else
                Pus.NeedleDim(dxf, new Line(zi5, zi6), new Line(new Vector2(zi6.X, zi6.Y), fun.Polar(new Vector2(zi6.X, zi6.Y), pi / 2, 1)), offset, "λs=" + Math.Round(lambdas * 180 / pi, 2) + "°", dimensionStyle);
            LinearDimension dim_s = new LinearDimension(new Line(zii6, zi6), offset * 0.7, Pus.Degree(zi6, zi5) + 90, dimensionStyle);
            fun.dxflinedim(dxf, dim_s, s);
            //后角
            if (alphan == 0)
                Pus.NeedleDim(dxf, new Line(new Vector2(zi6.X, zi6.Y), fun.Polar(new Vector2(zi6.X, zi6.Y), Pus.Degree(zi6, zi5) * pi / 180 + pi / 2 + pi / 180, 1)), new Line(zii6, zi6), offset * 0.5, "αn=0°", dimensionStyle);
            else
                Pus.NeedleDim(dxf, new Line(new Vector2(zi6.X, zi6.Y), fun.Polar(new Vector2(zi6.X, zi6.Y), Pus.Degree(zi6, zi5) * pi / 180 + pi / 2, 1)), new Line(zii6, zi6), offset * 0.5, "αn=" + Math.Round(alphan * 180 / pi, 2) + "°", dimensionStyle);
            //图框
            if (Convert.ToDouble(data["isframe"]) == 1)
            {
                Vector2 c4c = new Vector2((b2.X + zb3.X) / 2, (b2.Y + mu1.Y) / 2);
                Dictionary<string, Vector2> positions = Frame.frameA3X(dxf, new Vector2(c4c.X - 420 / 2, c4c.Y + 297 / 2), new Dictionary<string, object>());
                fun.writetextofC(dxf, kscale + ":1", positions["比例"], 3.5, 0, 0.6, 3);
            }

            dxf.DrawingVariables.AcadVer = DxfVersion.AutoCad2007;
            dxf.Save(path);
        }
        //N型刀头 横小
        public static void StyleN_InsertD(Dictionary<string, Object> data)
        {
            DxfDocument dxf = new DxfDocument();
            Layer contour = new Layer("contour") { Color = AciColor.Cyan };    //1,轮廓层
            Layer cutting = new Layer("cutting") { Color = AciColor.Red };    //切削层
            cutting.Lineweight = Lineweight.W200;

            string path = Convert.ToString(data["path"]);
            //参数名称取自ISO 5610
            double b = 8;
            double l1 = 100;
            double l2 = 25;
            double f = 4;
            double l3 = 7.75;
            double h2 = 8;
            double h1 = 8;
            double s = 2.38;
            double insertAngle = 55 * pi / 180;
            double alphan = 0 * pi / 180;
            double cutagl = 62.5 * pi / 180;
            double lambdas = 7 * pi / 180;
            double gammao = 4 * pi / 180;
            double repsilon = 0.3;
            #region
            try
            {
                if (data["re"] != null)
                    repsilon = Convert.ToDouble(data["re"]);
                if (repsilon <= 0)
                    repsilon = 0.01;
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["lams"] != null)
                    lambdas = Convert.ToDouble(data["lams"]) * pi / 180;
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["gamo"] != null)
                    gammao = Convert.ToDouble(data["gamo"]) * pi / 180;
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["b"] != null)
                    b = Convert.ToDouble(data["b"]);
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["s"] != null)
                    s = Convert.ToDouble(data["s"]);
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["lf"] != null)
                    l1 = Convert.ToDouble(data["lf"]);
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["lh"] != null)
                    l2 = Convert.ToDouble(data["lh"]);
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["wf"] != null)
                    f = Convert.ToDouble(data["wf"]);
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["h"] != null)
                    h2 = Convert.ToDouble(data["h"]);
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["hf"] != null)
                    h1 = Convert.ToDouble(data["hf"]);
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["epsr"] != null)
                    insertAngle = Convert.ToDouble(data["epsr"]) * pi / 180;
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["kapr"] != null)
                    cutagl = Convert.ToDouble(data["kapr"]) * pi / 180;
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["an"] != null)
                    alphan = Convert.ToDouble(data["an"]) * pi / 180;
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["ic"] != null)
                    l3 = Convert.ToDouble(data["l"]);
            }
            catch (KeyNotFoundException) { }
            #endregion
            double kscale = 1;
            if (l1 >= 120)
                kscale = 1;
            else
                kscale = 1.5;
            double lineWidth = 1;
            //k点位置恒定
            Vector3 k = new Vector3(0, 0, 0);
            RectShank rs = new RectShank(b, l1, f, l2, l3, 4, true, insertAngle, cutagl, lambdas, true, gammao, alphan, s, repsilon);
            Vector3[] shank = rs.Shank;
            Vector3[] inserts = rs.Inserts;
            //线性变换
            double theta = 0 * pi / 180;
            Matrix3 linearTrans = new Matrix3(
                Math.Cos(theta) * kscale, -Math.Sin(theta) * kscale, 0,
                Math.Sin(theta) * kscale, Math.Cos(theta) * kscale, 0,
                              0, 0, kscale
            );
            for (int i = 0; i < shank.Length; i++)
            {
                shank[i] = linearTrans * shank[i];
            }
            for (int i = 0; i < inserts.Length; i++)
            {
                inserts[i] = linearTrans * inserts[i];
            }
            repsilon *= kscale;

            Vector3[] head = new Vector3[9];
            Face3d fiu = new Face3d(inserts[4], inserts[5], inserts[6], inserts[7]);
            Face3d fb = new Face3d(shank[0], shank[1], shank[2]);
            Face3d ff = new Face3d(shank[0], shank[4], shank[7]);
            Face3d fbk = new Face3d(shank[1], shank[2], shank[6]);
            Face3d fc = new Face3d(Pus.ReferenceV3(shank[6], -kscale, 0, 0), Pus.ReferenceV3(shank[7], -kscale, 0, 0), Pus.ReferenceV3(shank[2], -kscale, 0, 0));
            Vector3 nbu = shank[4] - shank[0];
            head[0] = Pus.Inters(fb, inserts[0], inserts[0] + nbu);
            Face3d fd0 = new Face3d(inserts[0], head[0], inserts[1]);
            Face3d fd1 = new Face3d(inserts[0], head[0], inserts[3]);
            head[1] = Pus.Inters(ff, Pus.Inters(fd0, fb, head[0]));
            head[2] = Pus.Inters(fbk, Pus.Inters(fd1, fb, head[0]));
            head[3] = Pus.Inters(fd0, inserts[5], inserts[6]);
            head[4] = Pus.Inters(fiu, Pus.Inters(fd0, ff, head[1]));
            head[5] = Pus.Inters(fc, Pus.Inters(fiu, ff, head[4]));
            head[8] = Pus.Inters(fd1, inserts[6], inserts[7]);
            head[7] = Pus.Inters(fiu, Pus.Inters(fd1, fbk, head[2]));
            head[6] = Pus.Inters(fc, Pus.Inters(fbk, fiu, head[7]));

            //mview
            LwPolyline msk = Pus.AddPointsToLwPolyLine(shank[4], shank[5], shank[6], shank[7]);
            msk.IsClosed = true;
            fun.PolyFill(dxf, msk, lineWidth, contour);

            LwPolyline mfcon = Pus.AddPointsToLwPolyLine(head[5], head[6], shank[6], shank[7]);
            mfcon.IsClosed = true;
            fun.PolyFill(dxf, mfcon, lineWidth, contour);

            LwPolyline mfiu = Pus.AddPointsToLwPolyLine(inserts[6], head[3], head[4], head[5], head[6], head[7], head[8]);
            mfiu.IsClosed = true;
            fun.PolyFill(dxf, mfiu, lineWidth, contour);

            LwPolyline mist = Pus.AddPointsToLwPolyLine(inserts[4], inserts[5], inserts[6], inserts[7]);
            mist.IsClosed = true;
            Pus.AglToArc(mist, repsilon);
            fun.PolyFill(dxf, mist, lineWidth, cutting);

            //mview标注
            DimensionStyle dimensionStyle = new DimensionStyle("mystyle");
            dimensionStyle.ArrowSize = kscale * 1.5;
            dimensionStyle.DimArrow1 = DimensionArrowhead.Closedfilled;
            dimensionStyle.DimArrow2 = DimensionArrowhead.Closedfilled;
            dimensionStyle.TextHeight = kscale * 1.5;
            dimensionStyle.TextOffset = kscale;
            double offset = 7 * kscale;
            LinearDimension dim_b = new LinearDimension(new Line(shank[5], shank[4]), offset, Pus.Degree(shank[5], shank[4]), dimensionStyle);
            fun.dxflinedim(dxf, dim_b, b);
            LinearDimension dim_f = new LinearDimension(new Line(Vector3.Zero, head[7]), head[7].X / 2 + offset, Pus.Degree(shank[4], shank[5]), dimensionStyle);
            fun.dxflinedim(dxf, dim_f, f);
            LinearDimension dim_l1 = new LinearDimension(new Line(Vector3.Zero, shank[4]), b / 2 * kscale + offset, 180, dimensionStyle);
            fun.dxflinedim(dxf, dim_l1, l1);
            LinearDimension dim_l2 = new LinearDimension(new Line(shank[6], Vector3.Zero), shank[6].Y / 2 + offset, 0, dimensionStyle);
            fun.dxflinedim(dxf, dim_l2, l2);
            Angular2LineDimension dim_cutagl = new Angular2LineDimension(new Line(inserts[4], inserts[5]),
                new Line(Pus.ToV2(inserts[4]), fun.Polar(Pus.ToV2(inserts[4]), -pi / 2, 1)), offset, dimensionStyle);
            dim_cutagl.UserText = Math.Round(cutagl * 180 / pi, 1) + "°";
            dxf.AddEntity(dim_cutagl);

            //zview
            //绕y轴旋转pi/2再平移得到左视图
            Vector3[] zshank = new Vector3[shank.Length];
            Vector3[] zhead = new Vector3[head.Length];
            Vector3[] zinserts = new Vector3[inserts.Length];
            Vector3 zviewMkr = new Vector3(0, 1, 0);
            double yR = pi / 2;
            double zoffset = -2 * b * kscale;
            for (int i = 0; i < shank.Length; i++)
            {
                zshank[i] = Pus.Rodrigue(zviewMkr, 1, yR, shank[i]);
                zshank[i].X += zoffset;
            }
            for (int i = 0; i < inserts.Length; i++)
            {
                zinserts[i] = Pus.Rodrigue(zviewMkr, 1, yR, inserts[i]);
                zinserts[i].X += zoffset;
            }
            for (int i = 0; i < head.Length; i++)
            {
                zhead[i] = Pus.Rodrigue(zviewMkr, 1, yR, head[i]);
                zhead[i].X += zoffset;
            }
            Vector3 zk = k;
            zk.X += zoffset;

            LwPolyline zfd1 = Pus.AddPointsToLwPolyLine(zinserts[0], zhead[0], zhead[2], zhead[7], zhead[8]);
            fun.PolyFill(dxf, zfd1, lineWidth, contour);

            LwPolyline zfd0 = Pus.AddPointsToLwPolyLine(zinserts[0], zhead[0], zhead[1], zhead[4], zhead[3]);
            fun.PolyFill(dxf, zfd0, lineWidth, contour);

            LwPolyline zist0 = Pus.AddPointsToLwPolyLine(zinserts[0], zinserts[3], zinserts[7], zinserts[4]);
            zist0.IsClosed = true;
            fun.PolyFill(dxf, zist0, lineWidth, cutting);

            LwPolyline zist1 = Pus.AddPointsToLwPolyLine(zinserts[0], zinserts[1], zinserts[5], zinserts[4]);
            zist1.IsClosed = true;
            fun.PolyFill(dxf, zist1, lineWidth, cutting);

            if (zinserts[6].X > zinserts[4].X)
            {
                LwPolyline zfiu = Pus.AddPointsToLwPolyLine(zinserts[6], zhead[3], zhead[4], zhead[5], zhead[6], zhead[7], zhead[8]);
                zfiu.IsClosed = true;
                fun.PolyFill(dxf, zfiu, lineWidth, contour);

                LwPolyline zist = Pus.AddPointsToLwPolyLine(zinserts[4], zinserts[5], zinserts[6], zinserts[7]);
                zist.IsClosed = true;
                fun.PolyFill(dxf, zist, lineWidth, cutting);
            }

            //zview标注
            Vector2 z4 = Pus.ToV2(zinserts[4]);
            if (gammao == 0)
            {
                gammao = 0.1 * pi / 180;
                Pus.NeedleDim(dxf, new Line(z4, fun.Polar(z4, pi / 2, 1)),
                    new Line(z4, fun.Polar(z4, pi / 2 + gammao, 1)), offset * 1.7, "γo=0°", dimensionStyle);
            }
            else
            {
                Pus.NeedleDim(dxf, new Line(z4, fun.Polar(z4, pi / 2, 1)),
                    new Line(z4, fun.Polar(z4, pi / 2 + gammao, 1)), offset * 1.7, "γo=" + Math.Round(gammao * 180 / pi, 2) + "°", dimensionStyle);
            }

            //lview
            Vector3[] lshank = new Vector3[shank.Length];
            Vector3[] linserts = new Vector3[inserts.Length];
            Vector3[] lhead = new Vector3[head.Length];
            //放倒
            Vector3 laydown = new Vector3(-1, 0, 0);
            double laydownR = pi / 2;
            double loffset = -h2 * 2 * kscale;
            for (int i = 0; i < shank.Length; i++)
            {
                lshank[i] = Pus.Rodrigue(laydown, 1, laydownR, shank[i]);
                lshank[i].Y += loffset;
            }

            for (int i = 0; i < inserts.Length; i++)
            {
                linserts[i] = Pus.Rodrigue(laydown, 1, laydownR, inserts[i]);
                linserts[i].Y += loffset;
            }

            for (int i = 0; i < head.Length; i++)
            {
                lhead[i] = Pus.Rodrigue(laydown, 1, laydownR, head[i]);
                lhead[i].Y += loffset;
            }
            Vector3 lk = k;
            lk.Y += loffset;

            LwPolyline lff = Pus.AddPointsToLwPolyLine(lshank[0], lshank[4], lshank[7], lhead[5], lhead[4], lhead[1]);
            lff.IsClosed = true;
            fun.PolyFill(dxf, lff, lineWidth, contour);

            LwPolyline lfd0 = Pus.AddPointsToLwPolyLine(linserts[0], lhead[0], lhead[1], lhead[4], lhead[3], linserts[1]);
            lfd0.IsClosed = true;
            fun.PolyFill(dxf, lfd0, lineWidth, contour);

            LwPolyline list0 = Pus.AddPointsToLwPolyLine(linserts[0], linserts[1], linserts[5], linserts[4]);
            list0.IsClosed = true;
            fun.PolyFill(dxf, list0, lineWidth, cutting);

            if (linserts[7].Y > linserts[5].Y)
            {
                LwPolyline lfiu = Pus.AddPointsToLwPolyLine(linserts[6], lhead[3], lhead[4], lhead[5], lhead[6], lhead[7], lhead[8]);
                lfiu.IsClosed = true;
                fun.PolyFill(dxf, lfiu, lineWidth, contour);

                LwPolyline lfcon = Pus.AddPointsToLwPolyLine(lhead[5], lhead[6], lshank[6], lshank[7]);
                lfcon.IsClosed = true;
                fun.PolyFill(dxf, lfcon, lineWidth, contour);

                LwPolyline listu = Pus.AddPointsToLwPolyLine(linserts[4], linserts[5], linserts[6], linserts[7]);
                listu.IsClosed = true;
                fun.PolyFill(dxf, listu, lineWidth, cutting);

            }

            //lview标注
            Vector2 list4 = Pus.ToV2(linserts[4]);
            if (lambdas == 0)
            {
                lambdas = 0.1 * pi / 180;
                Pus.NeedleDim(dxf, new Line(linserts[5], linserts[4]),
                    new Line(list4, fun.Polar(list4, Pus.AngleOnP(linserts[5], linserts[4]) + lambdas, 1)), offset * 1.5, "λs=0°", dimensionStyle);
            }
            else
            {
                Pus.NeedleDim(dxf, new Line(linserts[5], linserts[4]),
                    new Line(list4, fun.Polar(list4, Pus.AngleOnP(linserts[5], linserts[4]) + lambdas, 1)), offset * 1.5, "λs=" + Math.Round(lambdas * 180 / pi, 2) + "°", dimensionStyle);
            }

            LinearDimension dim_h1 = new LinearDimension(new Line(lhead[0], lk), offset, Pus.Degree(lshank[0], lshank[4]), dimensionStyle);
            fun.dxflinedim(dxf, dim_h1, h1);
            LinearDimension dim_h2 = new LinearDimension(new Line(lshank[4], lshank[0]), offset, Pus.Degree(lshank[4], lshank[0]), dimensionStyle);
            fun.dxflinedim(dxf, dim_h2, h2);

            //图框
            Vector2 a3xsize = Frame.A3X;
            double isframe = 0;
            try
            {
                isframe = Convert.ToDouble(data["isframe"]);
            }
            catch (KeyNotFoundException) { }
            if (isframe != 0)
            {
                Vector2 EntitysCenter = new Vector2((shank[4].X + zhead[0].X) / 2, (shank[4].Y + lshank[0].Y) / 2);
                Vector2 p0 = new Vector2(EntitysCenter.X - a3xsize.X / 2, EntitysCenter.Y + a3xsize.Y / 2);
                Dictionary<string, Vector2> positions = Frame.frameA3X(dxf, p0);
                Vector2 kp = p0;
                try
                {
                    kp = positions["比例"];
                    fun.writetextofC(dxf, kscale + ":1", positions["比例"], 3.5, 0, 0.6, 3);
                }
                catch (Exception) { }
            }

            dxf.DrawingVariables.AcadVer = DxfVersion.AutoCad2007;
            dxf.Save(path);
        }
        public static void StyleN_InsertT(Dictionary<string, Object> data)
        {
            DxfDocument dxf = new DxfDocument();
            Layer contour = new Layer("contour") { Color = AciColor.Cyan };    //1,轮廓层
            Layer cutting = new Layer("cutting") { Color = AciColor.Red };    //切削层
            cutting.Lineweight = Lineweight.W200;

            string path = Convert.ToString(data["path"]);
            double pi = Math.PI;
            //参数名称取自ISO 5610-4
            double b = 25;
            double l1 = 100;
            double l2 = 32;
            double f = 12.5;
            double l3 = 16.5;
            double h2 = 25;
            double h1 = 25;
            double s = 3.97;
            double insertAngle = 60 * pi / 180;
            double alphan = 0 * pi / 180;
            double cutagl = 63 * pi / 180;
            double lambdas = 0;
            double gammao = 0;
            double repsilon = 0;
            #region
            try
            {
                if (data["re"] != null)
                    repsilon = Convert.ToDouble(data["re"]);
                if (repsilon <= 0)
                    repsilon = 0.01;
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["lams"] != null)
                    lambdas = Convert.ToDouble(data["lams"]) * pi / 180;
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["gamo"] != null)
                    gammao = Convert.ToDouble(data["gamo"]) * pi / 180;
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["b"] != null)
                    b = Convert.ToDouble(data["b"]);
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["s"] != null)
                    s = Convert.ToDouble(data["s"]);
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["lf"] != null)
                    l1 = Convert.ToDouble(data["lf"]);
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["lh"] != null)
                    l2 = Convert.ToDouble(data["lh"]);
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["wf"] != null)
                    f = Convert.ToDouble(data["wf"]);
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["h"] != null)
                    h2 = Convert.ToDouble(data["h"]);
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["hf"] != null)
                    h1 = Convert.ToDouble(data["hf"]);
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["epsr"] != null)
                    insertAngle = Convert.ToDouble(data["epsr"]) * pi / 180;
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["kapr"] != null)
                    cutagl = Convert.ToDouble(data["kapr"]) * pi / 180;
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["an"] != null)
                    alphan = Convert.ToDouble(data["an"]) * pi / 180;
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["ic"] != null)
                    l3 = Pus.GetLByTIC(Convert.ToDouble(data["ic"]));
            }
            catch (KeyNotFoundException) { }
            #endregion
            double kscale = 1;
            if (l1 >= 120)
                kscale = 1;
            else
                kscale = 1.5;
            double lineWidth = 1;
            //k点位置恒定
            Vector3 k = new Vector3(0, 0, 0);
            RectShank rs = new RectShank(b, l1, f, l2, l3, 3, true, insertAngle, cutagl, lambdas, true, gammao, alphan, s, repsilon);
            Vector3[] shank = rs.Shank;
            Vector3[] inserts = rs.Inserts;
            int icp = rs.InsertShape;
            //线性变换
            double theta = 0 * pi / 180;
            Matrix3 linearTrans = new Matrix3(
                Math.Cos(theta) * kscale, -Math.Sin(theta) * kscale, 0,
                Math.Sin(theta) * kscale, Math.Cos(theta) * kscale, 0,
                              0, 0, kscale
            );
            for (int i = 0; i < shank.Length; i++)
            {
                shank[i] = linearTrans * shank[i];
            }
            for (int i = 0; i < inserts.Length; i++)
            {
                inserts[i] = linearTrans * inserts[i];
            }
            repsilon *= kscale;

            Vector3[] head = new Vector3[9];
            Face3d fiu = new Face3d(inserts[3], inserts[4], inserts[5]);//循环
            Face3d fb = new Face3d(shank[0], shank[1], shank[2]);
            Face3d ff = new Face3d(shank[0], shank[4], shank[7]);
            Face3d fbk = new Face3d(shank[1], shank[2], shank[6]);
            Face3d fc = new Face3d(Pus.ReferenceV3(shank[6], -kscale, 0, 0), Pus.ReferenceV3(shank[7], -kscale, 0, 0), Pus.ReferenceV3(shank[2], -kscale, 0, 0));
            Vector3 nbu = shank[4] - shank[0];
            head[0] = Pus.Inters(fb, inserts[0], inserts[0] + nbu);
            Face3d fd0 = new Face3d(inserts[0], head[0], inserts[1]);
            Face3d fd1 = new Face3d(inserts[0], head[0], inserts[icp - 1]);
            head[1] = Pus.Inters(ff, Pus.Inters(fd0, fb, head[0]));
            head[2] = Pus.Inters(fbk, Pus.Inters(fd1, fb, head[0]));
            head[3] = Pus.Inters(fd0, inserts[icp + 1], inserts[icp + 2]);
            head[4] = Pus.Inters(fiu, Pus.Inters(fd0, ff, head[1]));
            head[5] = Pus.Inters(fc, Pus.Inters(fiu, ff, head[4]));
            head[8] = Pus.Inters(fd1, inserts[icp + 1], inserts[icp + 2]);
            head[7] = Pus.Inters(fiu, Pus.Inters(fd1, fbk, head[2]));
            head[6] = Pus.Inters(fc, Pus.Inters(fbk, fiu, head[7]));

            //mview
            LwPolyline msk = Pus.AddPointsToLwPolyLine(shank[4], shank[5], shank[6], shank[7]);
            msk.IsClosed = true;
            fun.PolyFill(dxf, msk, lineWidth, contour);

            LwPolyline mfcon = Pus.AddPointsToLwPolyLine(head[5], head[6], shank[6], shank[7]);
            mfcon.IsClosed = true;
            fun.PolyFill(dxf, mfcon, lineWidth, contour);

            LwPolyline mfiu = Pus.AddPointsToLwPolyLine(head[3], head[4], head[5], head[6], head[7], head[8]);
            mfiu.IsClosed = true;
            fun.PolyFill(dxf, mfiu, lineWidth, contour);

            LwPolyline mist = Pus.AddPointsToLwPolyLine(inserts[3], inserts[4], inserts[5]);
            mist.IsClosed = true;
            Pus.AglToArc(mist, repsilon);
            fun.PolyFill(dxf, mist, lineWidth, cutting);

            //mview标注
            DimensionStyle dimensionStyle = new DimensionStyle("mystyle");
            dimensionStyle.ArrowSize = kscale * 1.5;
            dimensionStyle.DimArrow1 = DimensionArrowhead.Closedfilled;
            dimensionStyle.DimArrow2 = DimensionArrowhead.Closedfilled;
            dimensionStyle.TextHeight = kscale * 1.5;
            dimensionStyle.TextOffset = kscale;
            double offset = 7 * kscale;
            LinearDimension dim_b = new LinearDimension(new Line(shank[5], shank[4]), offset, Pus.Degree(shank[5], shank[4]), dimensionStyle);
            fun.dxflinedim(dxf, dim_b, b);
            LinearDimension dim_f = new LinearDimension(new Line(Vector3.Zero, head[7]), head[7].X / 2 + offset, Pus.Degree(shank[4], shank[5]), dimensionStyle);
            fun.dxflinedim(dxf, dim_f, f);
            LinearDimension dim_l1 = new LinearDimension(new Line(Vector3.Zero, shank[4]), b / 2 * kscale + offset, 180, dimensionStyle);
            fun.dxflinedim(dxf, dim_l1, l1);
            LinearDimension dim_l2 = new LinearDimension(new Line(shank[6], Vector3.Zero), shank[6].Y / 2 + offset, 0, dimensionStyle);
            fun.dxflinedim(dxf, dim_l2, l2);
            Angular2LineDimension dim_cutagl = new Angular2LineDimension(new Line(inserts[icp], inserts[icp + 1]),
                new Line(Pus.ToV2(inserts[icp]), fun.Polar(Pus.ToV2(inserts[icp]), -pi / 2, 1)), offset, dimensionStyle);
            dim_cutagl.UserText = Math.Round(cutagl * 180 / pi, 1) + "°";
            dxf.AddEntity(dim_cutagl);

            //zview
            //绕y轴旋转pi/2再平移得到左视图
            Vector3[] zshank = new Vector3[shank.Length];
            Vector3[] zhead = new Vector3[head.Length];
            Vector3[] zinserts = new Vector3[inserts.Length];
            Vector3 zviewMkr = new Vector3(0, 1, 0);
            double yR = pi / 2;
            double zoffset = -2 * b * kscale;
            for (int i = 0; i < shank.Length; i++)
            {
                zshank[i] = Pus.Rodrigue(zviewMkr, 1, yR, shank[i]);
                zshank[i].X += zoffset;
            }
            for (int i = 0; i < inserts.Length; i++)
            {
                zinserts[i] = Pus.Rodrigue(zviewMkr, 1, yR, inserts[i]);
                zinserts[i].X += zoffset;
            }
            for (int i = 0; i < head.Length; i++)
            {
                zhead[i] = Pus.Rodrigue(zviewMkr, 1, yR, head[i]);
                zhead[i].X += zoffset;
            }
            Vector3 zk = k;
            zk.X += zoffset;

            LwPolyline zfd1 = Pus.AddPointsToLwPolyLine(zinserts[0], zhead[0], zhead[2], zhead[7], zhead[8]);
            fun.PolyFill(dxf, zfd1, lineWidth, contour);

            LwPolyline zfd0 = Pus.AddPointsToLwPolyLine(zinserts[0], zhead[0], zhead[1], zhead[4], zhead[3]);
            fun.PolyFill(dxf, zfd0, lineWidth, contour);

            LwPolyline zist0 = Pus.AddPointsToLwPolyLine(zinserts[0], zinserts[icp], zinserts[icp + 1], zinserts[1]);
            zist0.IsClosed = true;
            fun.PolyFill(dxf, zist0, lineWidth, cutting);

            LwPolyline zist1 = Pus.AddPointsToLwPolyLine(zinserts[0], zinserts[icp], zinserts[icp * 2 - 1], zinserts[icp - 1]);
            zist1.IsClosed = true;
            fun.PolyFill(dxf, zist1, lineWidth, cutting);

            if (zinserts[icp + 1].X > zinserts[icp].X)
            {
                LwPolyline zfiu = Pus.AddPointsToLwPolyLine(zhead[3], zhead[4], zhead[5], zhead[6], zhead[7], zhead[8]);
                zfiu.IsClosed = true;
                fun.PolyFill(dxf, zfiu, lineWidth, contour);

                LwPolyline zist = Pus.AddPointsToLwPolyLine(zinserts[3], zinserts[4], zinserts[5]);//循环
                zist.IsClosed = true;
                fun.PolyFill(dxf, zist, lineWidth, cutting);
            }

            //zview标注
            Vector2 zicp = Pus.ToV2(zinserts[icp]);
            if (gammao == 0)
            {
                gammao = 0.1 * pi / 180;
                Pus.NeedleDim(dxf, new Line(zicp, fun.Polar(zicp, pi / 2, 1)),
                    new Line(zicp, fun.Polar(zicp, pi / 2 + gammao, 1)), offset * 1.7, "γo=0°", dimensionStyle);
            }
            else
            {
                Pus.NeedleDim(dxf, new Line(zicp, fun.Polar(zicp, pi / 2, 1)),
                    new Line(zicp, fun.Polar(zicp, pi / 2 + gammao, 1)), offset * 1.7, "γo=" + Math.Round(gammao * 180 / pi, 2) + "°", dimensionStyle);
            }

            //lview
            Vector3[] lshank = new Vector3[shank.Length];
            Vector3[] linserts = new Vector3[inserts.Length];
            Vector3[] lhead = new Vector3[head.Length];
            //放倒
            Vector3 laydown = new Vector3(-1, 0, 0);
            double laydownR = pi / 2;
            double loffset = -h2 * 2 * kscale;
            for (int i = 0; i < shank.Length; i++)
            {
                lshank[i] = Pus.Rodrigue(laydown, 1, laydownR, shank[i]);
                lshank[i].Y += loffset;
            }

            for (int i = 0; i < inserts.Length; i++)
            {
                linserts[i] = Pus.Rodrigue(laydown, 1, laydownR, inserts[i]);
                linserts[i].Y += loffset;
            }

            for (int i = 0; i < head.Length; i++)
            {
                lhead[i] = Pus.Rodrigue(laydown, 1, laydownR, head[i]);
                lhead[i].Y += loffset;
            }
            Vector3 lk = k;
            lk.Y += loffset;

            LwPolyline lff = Pus.AddPointsToLwPolyLine(lshank[0], lshank[4], lshank[7], lhead[5], lhead[4], lhead[1]);
            lff.IsClosed = true;
            fun.PolyFill(dxf, lff, lineWidth, contour);

            LwPolyline lfd0 = Pus.AddPointsToLwPolyLine(linserts[0], lhead[0], lhead[1], lhead[4], lhead[3], linserts[1]);
            lfd0.IsClosed = true;
            fun.PolyFill(dxf, lfd0, lineWidth, contour);

            LwPolyline list0 = Pus.AddPointsToLwPolyLine(linserts[0], linserts[icp], linserts[icp + 1], linserts[1]);
            list0.IsClosed = true;
            fun.PolyFill(dxf, list0, lineWidth, cutting);

            if (linserts[2 * icp - 1].Y > linserts[icp].Y)
            {
                LwPolyline lfiu = Pus.AddPointsToLwPolyLine(lhead[3], lhead[4], lhead[5], lhead[6], lhead[7], lhead[8]);
                lfiu.IsClosed = true;
                fun.PolyFill(dxf, lfiu, lineWidth, contour);

                LwPolyline lfcon = Pus.AddPointsToLwPolyLine(lhead[5], lhead[6], lshank[6], lshank[7]);
                lfcon.IsClosed = true;
                fun.PolyFill(dxf, lfcon, lineWidth, contour);

                LwPolyline listu = Pus.AddPointsToLwPolyLine(linserts[3], linserts[4], linserts[5]);//循环
                listu.IsClosed = true;
                fun.PolyFill(dxf, listu, lineWidth, cutting);

            }

            //lview标注
            Vector2 licp = Pus.ToV2(linserts[icp]);
            if (lambdas == 0)
            {
                lambdas = 0.1 * pi / 180;
                Pus.NeedleDim(dxf, new Line(linserts[icp + 1], linserts[icp]),
                    new Line(licp, fun.Polar(licp, Pus.AngleOnP(linserts[icp + 1], linserts[icp]) + lambdas, 1)), offset * 1.5, "λs=0°", dimensionStyle);
            }
            else
            {
                Pus.NeedleDim(dxf, new Line(linserts[icp + 1], linserts[icp]),
                    new Line(licp, fun.Polar(licp, Pus.AngleOnP(linserts[icp + 1], linserts[icp]) + lambdas, 1)), offset * 1.5, "λs=" + Math.Round(lambdas * 180 / pi, 2) + "°", dimensionStyle);
            }

            LinearDimension dim_h1 = new LinearDimension(new Line(lhead[0], lk), offset, Pus.Degree(lshank[0], lshank[4]), dimensionStyle);
            fun.dxflinedim(dxf, dim_h1, h1);
            LinearDimension dim_h2 = new LinearDimension(new Line(lshank[4], lshank[0]), offset, Pus.Degree(lshank[4], lshank[0]), dimensionStyle);
            fun.dxflinedim(dxf, dim_h2, h2);

            //图框
            Vector2 a3xsize = Frame.A3X;
            double isframe = 0;
            try
            {
                isframe = Convert.ToDouble(data["isframe"]);
            }
            catch (KeyNotFoundException) { }
            if (isframe != 0)
            {
                Vector2 EntitysCenter = new Vector2((shank[4].X + zhead[0].X) / 2, (shank[4].Y + lshank[0].Y) / 2);
                Vector2 p0 = new Vector2(EntitysCenter.X - a3xsize.X / 2, EntitysCenter.Y + a3xsize.Y / 2);
                Dictionary<string, Vector2> positions = Frame.frameA3X(dxf, p0);
                Vector2 kp = p0;
                try
                {
                    kp = positions["比例"];
                    fun.writetextofC(dxf, kscale + ":1", positions["比例"], 3.5, 0, 0.6, 3);
                }
                catch (Exception) { }
            }

            dxf.DrawingVariables.AcadVer = DxfVersion.AutoCad2007;
            dxf.Save(path);
        }
        //T型刀头 横小
        public static void StyleT_InsertT(Dictionary<string, Object> data)
        {
            DxfDocument dxf = new DxfDocument();
            Layer contour = new Layer("contour") { Color = AciColor.Cyan };    //1,轮廓层
            Layer hatching = new Layer("hatching") { Color = AciColor.Blue };    //填充层
            Layer cutting = new Layer("cutting") { Color = AciColor.Red };    //切削层
            cutting.Lineweight = Lineweight.W200;

            string path = Convert.ToString(data["path"]);
            //参数名称取自ISO 5610-4
            double b = 12;
            double l1 = 100;
            double l2 = 25;
            double f = 11;
            double l3 = 11;
            double h2 = 12;
            double h1 = 12;
            double s = 2.38;
            double insertAngle = 60 * pi / 180;
            double alphan = 11 * pi / 180;
            double cutagl = 60 * pi / 180;
            double lambdas = 0;
            double gamao = 0;
            double repsilon = 0;
            #region 13399中的参数名称与之对应
            try
            {
                if (data["re"] != null)
                    repsilon = Convert.ToDouble(data["re"]);
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["lams"] != null)
                    lambdas = Convert.ToDouble(data["lams"]) * pi / 180;
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["gamo"] != null)
                    gamao = Convert.ToDouble(data["gamo"]) * pi / 180;
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["b"] != null)
                    b = Convert.ToDouble(data["b"]);
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["s"] != null)
                    s = Convert.ToDouble(data["s"]);
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["l"] != null)
                    l3 = Convert.ToDouble(data["l"]);
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["lf"] != null)
                    l1 = Convert.ToDouble(data["lf"]);
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["lh"] != null)
                    l2 = Convert.ToDouble(data["lh"]);
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["wf"] != null)
                    f = Convert.ToDouble(data["wf"]);
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["h"] != null)
                    h2 = Convert.ToDouble(data["h"]);
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["hf"] != null)
                    h1 = Convert.ToDouble(data["hf"]);
            }
            catch (KeyNotFoundException) { }
            //try
            //{
            //    if (data["epsr"] != null)
            //        insertAngle = Convert.ToDouble(data["epsr"]) * pi / 180;
            //}
            //catch (KeyNotFoundException) { }
            try
            {
                if (data["kapr"] != null)
                    cutagl = Convert.ToDouble(data["kapr"]) * pi / 180;
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["an"] != null)
                    alphan = Convert.ToDouble(data["an"]) * pi / 180;
            }
            catch (KeyNotFoundException) { }
            //Dictionary<double, double> l3_repsilon = new Dictionary<double, double> {
            //    { 11,0.4},
            //    { 16.5,0.8},
            //    { 22,0.8},
            //    { 27.5,1.2},
            //};
            #endregion
            //上部
            Vector2 c1 = new Vector2(0, 0);
            Vector2 c2 = new Vector2(c1.X - b, c1.Y);
            Vector2 c3 = new Vector2(c2.X, c2.Y - 3);
            Vector2 c4 = new Vector2(c3.X, c3.Y - h2);
            Vector2 c5 = new Vector2(c4.X, c4.Y - 3);
            Vector2 c6 = new Vector2(c1.X, c5.Y);
            Vector2 c7 = new Vector2(c6.X, c4.Y);
            Vector2 c8 = new Vector2(c7.X, c3.Y);
            LwPolyline upper = Pus.AddPointsToLwPolyLine(c6, c1, c2, c5);
            fun.PolyFill(dxf, upper, 0.1, contour);
            fun.drawPlinetype(dxf, new Vector2[] { c3, c8 }, 0.15, contour, Linetype.DashDot);
            fun.drawPlinetype(dxf, new Vector2[] { c4, c7 }, 0.15, contour, Linetype.DashDot);
            LwPolyline hatchLine = Pus.AddPointsToLwPolyLine(c8, c3, c4, c7);
            hatchLine.IsClosed = true;
            Pus.HatchByPath(dxf, new List<EntityObject> { hatchLine });
            dxf.AddEntity(Pus.TwoPointsWaveline(c5, c6, 12, 0.3));
            //下部
            Vector2 c9 = new Vector2(c5.X, c5.Y - 2);
            Vector2 c14 = new Vector2(c6.X, c6.Y - 2);
            dxf.AddEntity(Pus.TwoPointsWaveline(c9, c14, 12, 0.3));
            Vector2 c10 = new Vector2(c9.X, c9.Y - 5);
            Vector2 c13 = new Vector2(c14.X, c14.Y - 5);
            Pus.DrawPlineByTwoPoints(dxf, c10, c13);
            //k点位置参考ISO5610-1,i1与k点关系参考"横向进给，主偏角小于等于90度时K点位置.SLDPRT"
            Vector2 k = new Vector2(c2.X + f, c13.Y - l2);
            Vector2 i3 = fun.Polar(k, cutagl - pi, repsilon * (1 / Math.Tan(insertAngle / 2) - 1 / Math.Tan((pi - cutagl) / 2)));
            Vector2[] insertcontourPoints = Pus.ToVertical(i3, pi / 2, Pus.TrianglePoints(i3, l3, true, cutagl));
            Vector2 i1 = insertcontourPoints[1];
            Vector2 i2 = insertcontourPoints[2];
            LwPolyline insertcontour = Pus.AddPointsToLwPolyLine(insertcontourPoints);
            insertcontour.IsClosed = true;
            //倒圆角
            Pus.AglToArc(insertcontour, repsilon);
            fun.PolyFill(dxf, insertcontour, 0.1, contour);
            //底部按11度后角处理
            double insertoffset = s * Math.Tan(11 * pi / 180);
            Vector2[] buttomPoints = Pus.OffsetPoints(insertoffset, insertcontourPoints);
            //LwPolyline buttom = Pus.AddPointsToLwPolyLine(buttomPoints);
            //buttom.IsClosed = true;
            //buttom.Layer = cutting;
            //dxf.AddEntity(buttom);
            Vector2 ii1 = buttomPoints[1];
            Vector2 ii2 = buttomPoints[2];
            Vector2 ii3 = buttomPoints[0];
            Vector2 u1;
            Vector2 u2;
            Arc iarc1 = Pus.GetArcFromPline(insertcontour, 1);
            Arc iarc2 = Pus.GetArcFromPline(insertcontour, 2);
            List<Vector2> upoints1 = Pus.LineXArc(iarc2, ii1, ii3);
            if (upoints1 == null || upoints1.Count == 0)
                u1 = fun.Inters(i1, i2, ii1, ii3);
            else if (upoints1.Count == 1)
                u1 = upoints1[0];
            else
                u1 = upoints1[1];
            List<Vector2> upoints2 = Pus.LineXArc(iarc1, ii1, ii3);
            if (upoints2 == null || upoints2.Count == 0)
                u2 = fun.Inters(ii1, ii3, i2, i3);
            else
                u2 = upoints2[0];
            Vector2 c11 = fun.Inters(fun.Polar(u2, pi - pi / 180 * 10, 1), u2, c9, c10);
            Vector2 c12 = fun.Inters(fun.Polar(c13, -pi / 4, 1), c13, u1, fun.Polar(u1, pi / 2, 1));
            LwPolyline lower = Pus.AddPointsToLwPolyLine(c9, c11, u2, i2, u1, c12, c13, c14);
            fun.PolyFill(dxf, lower, 0.1, contour);
            //剖切符号
            Vector2 sp4a = Pus.KPoint(i3, i2, 0.1);
            Vector2 A_ = fun.Polar(sp4a, Vector2.Angle(i1, i3), 1);
            Vector2 ep4a = Pus.KPoint(i1, i2, 0.1);
            Vector2 _A = fun.Polar(ep4a, Vector2.Angle(i3, i1), 1);
            dxf.AddEntity(Pus.SectionSymbol(A_, _A, "A"));
            Vector2 B_ = fun.Polar(i2, Vector2.Angle(i3, i1) + pi / 2, 2);
            Vector2 _B = fun.Polar(Pus.KPoint(i3, i1, 0.5), Vector2.Angle(i3, i1) - pi / 2, 2);
            dxf.AddEntity(Pus.SectionSymbol(B_, _B, "B"));
            //标注
            DimensionStyle dimensionStyle = fun.CreateDimStyle();
            dimensionStyle.ArrowSize = 0.2;
            dimensionStyle.DimArrow1 = DimensionArrowhead.Closedfilled;
            dimensionStyle.DimArrow2 = DimensionArrowhead.Closedfilled;
            dimensionStyle.TextHeight = 0.5;
            double offset = 7;
            LinearDimension dim_l1 = new LinearDimension(new Line(k, c1), offset * 3, -90, dimensionStyle);
            fun.dxflinedim(dxf, dim_l1, l1);
            LinearDimension dim_l2 = new LinearDimension(new Line(k, c13), offset * 2, -90, dimensionStyle);
            fun.dxflinedim(dxf, dim_l2, l2);
            LinearDimension dim_f = new LinearDimension(new Line(k, c11), offset * 1.5, 180, dimensionStyle);
            fun.dxflinedim(dxf, dim_f, f);
            LinearDimension dim_h2 = new LinearDimension(new Line(c7, c8), 0.5 * offset, -90, dimensionStyle);
            fun.dxflinedim(dxf, dim_h2, h2);
            LinearDimension dim_b = new LinearDimension(new Line(c1, c2), offset * 0.5, 0, dimensionStyle);
            fun.dxflinedim(dxf, dim_b, b);
            Angular2LineDimension dim_cutAgl1 = new Angular2LineDimension(new Line(i3, i1), new Line(i3, fun.Polar(i3, 0, 1)), 3, dimensionStyle);
            dim_cutAgl1.UserText = cutagl * 180 / pi + "°";
            dxf.AddEntity(dim_cutAgl1);
            Angular2LineDimension dim_insertagl = new Angular2LineDimension(new Line(i3, i1), new Line(i3, i2), 3, dimensionStyle);
            dim_insertagl.UserText = insertAngle * 180 / pi + "°";
            dxf.AddEntity(dim_insertagl);
            RadialDimension dim_repsilon = new RadialDimension(Pus.GetArcFromPline(insertcontour, 1), -45, 5, dimensionStyle);
            dim_repsilon.UserText = "rε=" + repsilon;
            dxf.AddEntity(dim_repsilon);
            //刃倾角剖视图A-A
            //Dictionary<double, double> alphan_gamao = new Dictionary<double, double>() {
            //    { 7 * pi / 180,0},
            //    { 0,-6 * pi / 180},
            //    { 11 * pi / 180,5 * pi / 180},
            //};
            Vector2 a1 = new Vector2(c4.X - offset * 2.5, c5.Y);
            Vector2 a1p = fun.Polar(a1, 0, l3 * 2);
            Vector2 a5 = fun.Polar(a1, -lambdas, l3 - 2);
            Vector2 a2 = fun.Polar(a1, Vector2.Angle(a1, a5) - pi / 2 + alphan, s / Math.Cos(alphan));
            Vector2 a3 = fun.Polar(a2, Vector2.Angle(a1, a5) - pi / 2 + alphan, s * 3);
            Vector2 a4 = fun.Polar(a1, -lambdas, l3 + 2);

            Vector2 a6 = fun.Polar(a5, Vector2.Angle(a1, a5) - pi / 2 - alphan, s / Math.Cos(alphan));
            Vector2[] A_A = Pus.RotateByPoint(a1, pi / 2, a1, a2, a3, a4, a5, a6, a1p);
            //样条
            Spline spline1 = Pus.TwoPointsSpline(A_A[3], A_A[4], 9, 9);
            dxf.AddEntity(spline1);
            LwPolyline aa = Pus.AddPointsToLwPolyLine(A_A[4], A_A[5], A_A[6], A_A[2], A_A[3]);
            fun.PolyFill(dxf, aa, 0.1, contour);
            LwPolyline aainsert = Pus.AddPointsToLwPolyLine(A_A[1], A_A[2], A_A[6], A_A[5]);
            aainsert.IsClosed = true;
            fun.PolyFill(dxf, aainsert, 0.1, contour);
            //填充
            Pus.HatchByPath(dxf, new List<EntityObject> { aa, spline1 });
            Pus.HatchByPath(dxf, 130, 5, new List<EntityObject> { aainsert });
            //标注
            LinearDimension dim_s = new LinearDimension(new Line(A_A[1], A_A[2]), -offset, Vector2.Angle(A_A[1], A_A[5]) * 180 / pi - 90, dimensionStyle);
            fun.dxflinedim(dxf, dim_s, s);
            if (lambdas == 0)
                Pus.NeedleDim(dxf, new Line(A_A[1], A_A[4]), new Line(A_A[1], fun.Polar(A_A[1], Vector2.Angle(A_A[1], A_A[7]) + pi / 180, 1)), offset * 2, lambdas * 180 / pi + "°±1°", dimensionStyle);
            else
                Pus.NeedleDim(dxf, new Line(A_A[1], A_A[4]), new Line(A_A[1], A_A[7]), offset * 2, lambdas * 180 / pi + "°±1°", dimensionStyle);
            //A-A
            Text texta = new Text("A-A", fun.Polar(A_A[4], pi / 2, offset * 1.5), 2, 0);
            dxf.AddEntity(texta);
            string alphanSletter = "!";
            try
            {
                alphanSletter = alphan_p[alphan];
            }
            catch (Exception) { }
            Text textalpha = new Text("αn=" + alphan * 180 / pi + "°" + "(" + alphanSletter + ")", fun.Polar(A_A[1], pi * 3 / 4, offset * 2), 1, 0);
            dxf.AddEntity(textalpha);
            //B-B
            Vector2 b1 = new Vector2(c11.X - offset * 2, i1.Y);
            Vector2 b1p = fun.Polar(b1, 0, 1);
            Vector2 b6 = fun.Polar(b1, pi + gamao, l3 * 0.8);
            Vector2 b2 = fun.Polar(b1, Vector2.Angle(b1, b6) + pi / 2 - alphan, s / Math.Cos(alphan));
            Vector2 b3 = fun.Polar(b1, Vector2.Angle(b1, b6) + pi / 2 - alphan, h1 / Math.Cos(alphan));
            Vector2 b4 = fun.Polar(b3, pi, l3 + 2);
            Vector2 b5 = fun.Polar(b1, pi + gamao, l3 + 2);
            Vector2 b7 = fun.Polar(b6, Vector2.Angle(b1, b6) + pi / 2 + alphan, s / Math.Cos(alphan));
            Vector2[] B_B = Pus.RotateByPoint(b1, 0, b1, b2, b3, b4, b5, b6, b7, b1p);
            LwPolyline bcontour = Pus.AddPointsToLwPolyLine(B_B[4], B_B[3], B_B[2], B_B[7], B_B[6], B_B[5]);
            fun.PolyFill(dxf, bcontour, 0.1, contour);
            LwPolyline binsert = Pus.AddPointsToLwPolyLine(B_B[1], B_B[2], B_B[7], B_B[6]);
            binsert.IsClosed = true;
            fun.PolyFill(dxf, binsert, 0.1, contour);
            //样条
            Spline bcspline = Pus.TwoPointsSpline(B_B[4], B_B[5], 9, 9);
            dxf.AddEntity(bcspline);
            //填充
            List<HatchBoundaryPath> bboundary1 = new List<HatchBoundaryPath>();
            HatchBoundaryPath bcpath = new HatchBoundaryPath(new List<EntityObject> { bcontour, bcspline });
            bboundary1.Add(bcpath);
            Hatch bchatch = new Hatch(HatchPattern.Line, bboundary1, true);
            bchatch.Pattern.Scale = 8;
            bchatch.Pattern.Angle = 70;
            bchatch.Layer = hatching;
            dxf.AddEntity(bchatch);
            List<HatchBoundaryPath> bboundary2 = new List<HatchBoundaryPath>();
            HatchBoundaryPath bipath = new HatchBoundaryPath(new List<EntityObject> { binsert });
            bboundary2.Add(bipath);
            Hatch bihatch = new Hatch(HatchPattern.Line, bboundary2, true);
            bihatch.Pattern.Scale = 4;
            bihatch.Pattern.Angle = 120;
            bihatch.Layer = hatching;
            dxf.AddEntity(bihatch);
            //标注
            if (gamao == 0)
            {
                Pus.NeedleDim(dxf, new Line(B_B[5], B_B[1]), new Line(B_B[5], fun.Polar(B_B[5], Vector2.Angle(B_B[5], B_B[1]) + pi / 180, 1)), offset * 2, gamao * 180 / pi + "°±1°", dimensionStyle);
            }
            else
                Pus.NeedleDim(dxf, new Line(B_B[1], fun.Polar(B_B[1], Vector2.Angle(B_B[5], B_B[1]), 1)), new Line(B_B[1], B_B[8]), offset, gamao * 180 / pi + "°±1°", dimensionStyle);
            LinearDimension dim_h1 = new LinearDimension(new Line(B_B[1], B_B[3]), offset, -90, dimensionStyle);
            fun.dxflinedim(dxf, dim_h1, h1);
            //text
            Text textb = new Text("B-B", fun.Polar(B_B[6], pi / 2, offset * 0.7), 2, 0);
            Text textalphb = new Text("αn=" + alphan * 180 / pi + "°" + "(" + alphanSletter + ")", new Vector2(textb.Position.X, textb.Position.Y - 2), 1, 0);
            dxf.AddEntity(textb);
            dxf.AddEntity(textalphb);
            dxf.DrawingVariables.AcadVer = DxfVersion.AutoCad2007;
            dxf.Save(path);
        }
        public static void StyleT_InsertS(Dictionary<string, Object> data)
        {
            DxfDocument dxf = new DxfDocument();
            Layer contour = new Layer("contour") { Color = AciColor.Cyan };    //1,轮廓层
            Layer cutting = new Layer("cutting") { Color = AciColor.Red };    //切削层

            string path = Convert.ToString(data["path"]);
            //参数名称取自ISO 5610-4
            double b = 12;
            double l1 = 100;
            double l2 = 25;
            double f = 11;
            double l3 = 11;
            double h2 = 12;
            double h1 = 12;
            double s = 2.38;
            double insertAngle = 90 * pi / 180;
            double alphan = 7 * pi / 180;
            double cutagl = 60 * pi / 180;
            double lambdas = -6 * pi / 180;
            double gammao = -6 * pi / 180;
            double repsilon = 0;
            #region
            try
            {
                if (data["re"] != null)
                    repsilon = Convert.ToDouble(data["re"]);
                if (repsilon <= 0)
                    repsilon = 0.01;
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["lams"] != null)
                    lambdas = Convert.ToDouble(data["lams"]) * pi / 180;
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["gamo"] != null)
                    gammao = Convert.ToDouble(data["gamo"]) * pi / 180;
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["b"] != null)
                    b = Convert.ToDouble(data["b"]);
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["s"] != null)
                    s = Convert.ToDouble(data["s"]);
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["lf"] != null)
                    l1 = Convert.ToDouble(data["lf"]);
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["lh"] != null)
                    l2 = Convert.ToDouble(data["lh"]);
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["wf"] != null)
                    f = Convert.ToDouble(data["wf"]);
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["h"] != null)
                    h2 = Convert.ToDouble(data["h"]);
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["hf"] != null)
                    h1 = Convert.ToDouble(data["hf"]);
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["epsr"] != null)
                    insertAngle = Convert.ToDouble(data["epsr"]) * pi / 180;
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["kapr"] != null)
                    cutagl = Convert.ToDouble(data["kapr"]) * pi / 180;
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["an"] != null)
                    alphan = Convert.ToDouble(data["an"]) * pi / 180;
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["ic"] != null)
                    l3 = Pus.GetLByIC(Convert.ToDouble(data["ic"]), insertAngle);
            }
            catch (KeyNotFoundException) { }
            #endregion
            double kscale = 1;
            if (l1 >= 120)
                kscale = 1;
            else
                kscale = 1.5;
            double lineWidth = 1;
            //k点位置恒定
            Vector3 k = new Vector3(0, 0, 0);
            RectShank rs = new RectShank(b, l1, f, l2, l3, 4, true, insertAngle, cutagl, lambdas, true, gammao, alphan, s, repsilon);
            Vector3[] shank = rs.Shank;
            Vector3[] inserts = rs.Inserts;
            int icp = rs.InsertShape;
            //线性变换
            double theta = 0 * pi / 180;
            Matrix3 linearTrans = new Matrix3(
                Math.Cos(theta) * kscale, -Math.Sin(theta) * kscale, 0,
                Math.Sin(theta) * kscale, Math.Cos(theta) * kscale, 0,
                              0, 0, kscale
            );
            for (int i = 0; i < shank.Length; i++)
            {
                shank[i] = linearTrans * shank[i];
            }
            for (int i = 0; i < inserts.Length; i++)
            {
                inserts[i] = linearTrans * inserts[i];
            }
            repsilon *= kscale;

            Vector3[] head = new Vector3[15];
            Face3d fiu = new Face3d(inserts[icp + 1], inserts[icp + 2], inserts[icp + 3]);
            Face3d fb = new Face3d(shank[0], shank[1], shank[2]);
            Face3d ff = new Face3d(shank[0], shank[4], shank[7]);
            Face3d fbk = new Face3d(shank[1], shank[2], shank[6]);
            Face3d fc0 = new Face3d(Pus.ReferenceV3(shank[6], -kscale, 0, 0), Pus.ReferenceV3(shank[7], -kscale, 0, 0), Pus.ReferenceV3(shank[2], -kscale, 0, 0));
            Face3d fc1 = new Face3d(Pus.ReferenceV3(shank[6], -kscale * 1.5, 0, 0), Pus.ReferenceV3(shank[7], -kscale * 1.5, 0, 0), Pus.ReferenceV3(shank[2], -kscale * 1.5, 0, 0));
            Vector3 nbu = shank[4] - shank[0];
            head[0] = Pus.Inters(fb, inserts[0], inserts[0] + nbu);
            Face3d fd0 = new Face3d(inserts[0], head[0], inserts[1]);
            Face3d fd1 = new Face3d(inserts[0], head[0], inserts[icp - 1]);
            head[1] = Pus.Inters(fb, inserts[1], inserts[1] + nbu);
            Face3d ft = new Face3d(inserts[1], head[1], Pus.ReferenceV3(head[1], 1, 0, 0));
            head[2] = Pus.Inters(fc1, Pus.Inters(ft, fb, head[1]));
            head[3] = Pus.Inters(fbk, Pus.Inters(fd1, fb, head[0]));
            head[4] = Pus.Inters(ft, inserts[icp + 1], inserts[icp + 2]);
            head[5] = Pus.Inters(fc1, Pus.Inters(fiu, ft, head[4]));
            head[9] = Pus.Inters(fd1, inserts[icp + 3], inserts[icp + 2]);
            head[8] = Pus.Inters(fiu, Pus.Inters(fd1, fbk, head[3]));
            head[7] = Pus.Inters(fc0, Pus.Inters(fbk, fiu, head[8]));
            head[6] = Pus.Inters(ff, Pus.Inters(fiu, fc0, head[7]));
            head[10] = Pus.KPoint(head[9], head[8], 0.7);
            head[11] = Pus.KPoint(head[8], head[7], 0.2);
            head[12] = Pus.Inters(fb, head[11], head[11] + nbu);
            Face3d fec = new Face3d(head[10], head[11], head[12]);
            head[13] = Pus.Inters(fec, head[0], head[3]);
            head[14] = Pus.Inters(fb, head[6], head[6] + nbu);

            //mview
            LwPolyline msk = Pus.AddPointsToLwPolyLine(shank[4], shank[5], shank[6], shank[7]);
            msk.IsClosed = true;
            fun.PolyFill(dxf, msk, lineWidth, contour);

            LwPolyline mfcon = Pus.AddPointsToLwPolyLine(head[6], head[7], shank[6], shank[7]);
            mfcon.IsClosed = true;
            fun.PolyFill(dxf, mfcon, lineWidth, contour);

            LwPolyline mfiu = Pus.AddPointsToLwPolyLine(inserts[icp + 2], head[4], head[5], head[6], head[7], head[11], head[10], head[9]);
            mfiu.IsClosed = true;
            fun.PolyFill(dxf, mfiu, lineWidth, contour);

            LwPolyline mist = new LwPolyline();
            for (int i = icp; i < icp * 2; i++)
            {
                Pus.AddPointsToLwPolyLine(mist, inserts[i]);
            }
            mist.IsClosed = true;
            Pus.AglToArc(mist, repsilon);
            fun.PolyFill(dxf, mist, lineWidth, cutting);

            //mview标注
            DimensionStyle dimensionStyle = new DimensionStyle("mystyle");
            dimensionStyle.ArrowSize = kscale * 1.5;
            dimensionStyle.DimArrow1 = DimensionArrowhead.Closedfilled;
            dimensionStyle.DimArrow2 = DimensionArrowhead.Closedfilled;
            dimensionStyle.TextHeight = kscale * 1.5;
            dimensionStyle.TextOffset = kscale;
            double offset = 7 * kscale;
            LinearDimension dim_b = new LinearDimension(new Line(shank[5], shank[4]), offset, Pus.Degree(shank[5], shank[4]), dimensionStyle);
            fun.dxflinedim(dxf, dim_b, b);
            LinearDimension dim_f = new LinearDimension(new Line(Vector3.Zero, head[8]), head[8].X / 2 + offset, Pus.Degree(shank[4], shank[5]), dimensionStyle);
            fun.dxflinedim(dxf, dim_f, f);
            LinearDimension dim_l1 = new LinearDimension(new Line(Vector3.Zero, shank[4]), b / 2 * kscale + offset, 180, dimensionStyle);
            fun.dxflinedim(dxf, dim_l1, l1);
            LinearDimension dim_l2 = new LinearDimension(new Line(shank[6], Vector3.Zero), shank[6].Y / 2 + offset, 0, dimensionStyle);
            fun.dxflinedim(dxf, dim_l2, l2);
            Angular2LineDimension dim_cutagl = new Angular2LineDimension(new Line(inserts[icp], inserts[icp + 1]),
                new Line(Pus.ToV2(inserts[icp]), fun.Polar(Pus.ToV2(inserts[icp]), -pi / 2, 1)), offset, dimensionStyle);
            dim_cutagl.UserText = Math.Round(cutagl * 180 / pi, 1) + "°";
            dxf.AddEntity(dim_cutagl);

            //zview
            //绕y轴旋转pi/2再平移得到左视图
            Vector3[] zshank = new Vector3[shank.Length];
            Vector3[] zhead = new Vector3[head.Length];
            Vector3[] zinserts = new Vector3[inserts.Length];
            Vector3 zviewMkr = new Vector3(0, 1, 0);
            double yR = pi / 2;
            double zoffset = -2 * b * kscale;
            for (int i = 0; i < shank.Length; i++)
            {
                zshank[i] = Pus.Rodrigue(zviewMkr, 1, yR, shank[i]);
                zshank[i].X += zoffset;
            }
            for (int i = 0; i < inserts.Length; i++)
            {
                zinserts[i] = Pus.Rodrigue(zviewMkr, 1, yR, inserts[i]);
                zinserts[i].X += zoffset;
            }
            for (int i = 0; i < head.Length; i++)
            {
                zhead[i] = Pus.Rodrigue(zviewMkr, 1, yR, head[i]);
                zhead[i].X += zoffset;
            }
            Vector3 zk = k;
            zk.X += zoffset;

            LwPolyline zfd1 = Pus.AddPointsToLwPolyLine(zinserts[0], zhead[0], zhead[13], zhead[10], zhead[9]);
            fun.PolyFill(dxf, zfd1, lineWidth, contour);

            LwPolyline zfec = Pus.AddPointsToLwPolyLine(zhead[10], zhead[11], zhead[12], zhead[13]);
            zfec.IsClosed = true;
            fun.PolyFill(dxf, zfec, lineWidth, contour);

            LwPolyline zfd0 = Pus.AddPointsToLwPolyLine(zinserts[0], zhead[0], zhead[1], zinserts[1]);
            fun.PolyFill(dxf, zfd0, lineWidth, contour);

            LwPolyline zist0 = Pus.AddPointsToLwPolyLine(zinserts[0], zinserts[icp], zinserts[icp + 1], zinserts[1]);
            zist0.IsClosed = true;
            fun.PolyFill(dxf, zist0, lineWidth, cutting);

            LwPolyline zist1 = Pus.AddPointsToLwPolyLine(zinserts[0], zinserts[icp], zinserts[icp * 2 - 1], zinserts[icp - 1]);
            zist1.IsClosed = true;
            fun.PolyFill(dxf, zist1, lineWidth, cutting);

            if (zinserts[icp + 1].X > zinserts[icp].X)
            {
                LwPolyline zfiu = Pus.AddPointsToLwPolyLine(zhead[4], zhead[5], zhead[6], zhead[7], zhead[11], zhead[10], zhead[9]);
                fun.PolyFill(dxf, zfiu, lineWidth, contour);

                LwPolyline zist = new LwPolyline();
                for (int i = icp; i < icp * 2; i++)
                {
                    Pus.AddPointsToLwPolyLine(zist, zinserts[i]);
                }
                zist.IsClosed = true;
                fun.PolyFill(dxf, zist, lineWidth, cutting);
            }

            //zview标注
            Vector2 zicp = Pus.ToV2(zinserts[icp]);
            if (gammao == 0)
            {
                gammao = 0.1 * pi / 180;
                Pus.NeedleDim(dxf, new Line(zicp, fun.Polar(zicp, -pi / 2, 1)),
                    new Line(zicp, fun.Polar(zicp, -pi / 2 + gammao, 1)), offset * 1.7, "γo=0°", dimensionStyle);
            }
            else
            {
                Pus.NeedleDim(dxf, new Line(zicp, fun.Polar(zicp, -pi / 2, 1)),
                    new Line(zicp, fun.Polar(zicp, -pi / 2 + gammao, 1)), offset * 1.7, "γo=" + Math.Round(gammao * 180 / pi, 2) + "°", dimensionStyle);
            }

            //lview
            Vector3[] lshank = new Vector3[shank.Length];
            Vector3[] linserts = new Vector3[inserts.Length];
            Vector3[] lhead = new Vector3[head.Length];
            //放倒
            Vector3 laydown = new Vector3(-1, 0, 0);
            double laydownR = pi / 2;
            double loffset = -h2 * 2 * kscale;
            for (int i = 0; i < shank.Length; i++)
            {
                lshank[i] = Pus.Rodrigue(laydown, 1, laydownR, shank[i]);
                lshank[i].Y += loffset;
            }

            for (int i = 0; i < inserts.Length; i++)
            {
                linserts[i] = Pus.Rodrigue(laydown, 1, laydownR, inserts[i]);
                linserts[i].Y += loffset;
            }

            for (int i = 0; i < head.Length; i++)
            {
                lhead[i] = Pus.Rodrigue(laydown, 1, laydownR, head[i]);
                lhead[i].Y += loffset;
            }
            Vector3 lk = k;
            lk.Y += loffset;

            LwPolyline lff = Pus.AddPointsToLwPolyLine(lshank[0], lshank[4], lshank[7], lhead[6], lhead[14]);
            lff.IsClosed = true;
            fun.PolyFill(dxf, lff, lineWidth, contour);

            LwPolyline lfcon1 = Pus.AddPointsToLwPolyLine(lhead[6], lhead[5], lhead[2], lhead[14]);
            lfcon1.IsClosed = true;
            fun.PolyFill(dxf, lfcon1, lineWidth, contour);

            LwPolyline lft = Pus.AddPointsToLwPolyLine(lhead[1], lhead[2], lhead[5], lhead[4], linserts[1]);
            lft.IsClosed = true;
            fun.PolyFill(dxf, lft, lineWidth, contour);

            LwPolyline lfd0 = Pus.AddPointsToLwPolyLine(linserts[0], lhead[0], lhead[1], linserts[1]);
            fun.PolyFill(dxf, lfd0, lineWidth, contour);

            LwPolyline list0 = Pus.AddPointsToLwPolyLine(linserts[0], linserts[icp], linserts[icp + 1], linserts[1]);
            list0.IsClosed = true;
            fun.PolyFill(dxf, list0, lineWidth, cutting);

            if (linserts[2 * icp - 1].Y > linserts[icp].Y)
            {
                LwPolyline lfiu = Pus.AddPointsToLwPolyLine(lhead[4], lhead[5], lhead[6], lhead[7], lhead[11], lhead[10], lhead[9]);
                fun.PolyFill(dxf, lfiu, lineWidth, contour);

                LwPolyline lfcon = Pus.AddPointsToLwPolyLine(lhead[6], lhead[7], lshank[6], lshank[7]);
                lfcon.IsClosed = true;
                fun.PolyFill(dxf, lfcon, lineWidth, contour);

                LwPolyline listu = new LwPolyline();
                for (int i = icp; i < icp * 2; i++)
                {
                    Pus.AddPointsToLwPolyLine(listu, linserts[i]);
                }
                listu.IsClosed = true;
                fun.PolyFill(dxf, listu, lineWidth, cutting);

            }

            //lview标注
            Vector2 licp = Pus.ToV2(linserts[icp]);
            if (lambdas == 0)
            {
                lambdas = 0.1 * pi / 180;
                Pus.NeedleDim(dxf, new Line(linserts[icp + 1], linserts[icp]),
                    new Line(licp, fun.Polar(licp, Pus.AngleOnP(linserts[icp + 1], linserts[icp]) + lambdas, 1)), offset * 1.5, "λs=0°", dimensionStyle);
            }
            else
            {
                Pus.NeedleDim(dxf, new Line(linserts[icp + 1], linserts[icp]),
                    new Line(licp, fun.Polar(licp, Pus.AngleOnP(linserts[icp + 1], linserts[icp]) + lambdas, 1)), offset * 1.5, "λs=" + Math.Round(lambdas * 180 / pi, 2) + "°", dimensionStyle);
            }

            LinearDimension dim_h1 = new LinearDimension(new Line(lhead[0], lk), offset, Pus.Degree(lshank[0], lshank[4]), dimensionStyle);
            fun.dxflinedim(dxf, dim_h1, h1);
            LinearDimension dim_h2 = new LinearDimension(new Line(lshank[4], lshank[0]), offset, Pus.Degree(lshank[4], lshank[0]), dimensionStyle);
            fun.dxflinedim(dxf, dim_h2, h2);

            //图框
            Vector2 a3xsize = Frame.A3X;
            double isframe = 0;
            try
            {
                isframe = Convert.ToDouble(data["isframe"]);
            }
            catch (KeyNotFoundException) { }
            if (isframe != 0)
            {
                Vector2 EntitysCenter = new Vector2((shank[4].X + zhead[0].X) / 2, (shank[4].Y + lshank[0].Y) / 2);
                Vector2 p0 = new Vector2(EntitysCenter.X - a3xsize.X / 2, EntitysCenter.Y + a3xsize.Y / 2);
                Dictionary<string, Vector2> positions = Frame.frameA3X(dxf, p0);
                Vector2 kp = p0;
                try
                {
                    kp = positions["比例"];
                    fun.writetextofC(dxf, kscale + ":1", positions["比例"], 3.5, 0, 0.6, 3);
                }
                catch (Exception) { }
            }

            dxf.DrawingVariables.AcadVer = DxfVersion.AutoCad2007;
            dxf.Save(path);
        }
        #region pushuai`s methods
        //剖切符号
        public static EntityObject[] SectionSymbol(Vector2 startpoint, Vector2 endpoint, string c)
        {
            return SectionSymbol(startpoint, endpoint, c, 4, 1, 1);
        }
        public static EntityObject[] SectionSymbol(Vector2 startpoint, Vector2 endpoint, string c, double totalLength, double arrowheadLength, double textHeigth)
        {
            double s_e_a = Vector2.Angle(startpoint, endpoint);
            double rotateDegree = s_e_a * 180 / Math.PI + 90;
            Vector2 tailonstart = fun.Polar(startpoint, s_e_a + Math.PI, 2);
            Vector2 tailonend = fun.Polar(endpoint, s_e_a, 2);
            //箭头顶点
            Vector2 pointonstart = fun.Polar(tailonstart, rotateDegree * Math.PI / 180, totalLength);
            Solid[] startarrow = MyArrow(pointonstart, -90 + s_e_a * 180 / Math.PI, 1, totalLength);
            Solid startline = new Solid(startpoint, tailonstart, tailonstart);
            //箭头顶点
            Vector2 pointonend = fun.Polar(tailonend, rotateDegree * Math.PI / 180, totalLength);
            Solid[] endarrow = MyArrow(pointonend, -90 + s_e_a * 180 / Math.PI, 1, totalLength);
            Solid endline = new Solid(endpoint, tailonend, tailonend);
            //文字
            Text starttext = new Text(c, fun.Polar(pointonstart, s_e_a + Math.PI, 1.5), textHeigth, s_e_a * 180 / Math.PI);
            Text endtext = new Text(c, fun.Polar(pointonend, s_e_a, 1.5), textHeigth, s_e_a * 180 / Math.PI);
            return new EntityObject[] { startarrow[0], startarrow[1], startline, endarrow[0], endarrow[1], endline, starttext, endtext };
        }
        //箭头
        public static Solid[] MyArrow(Vector2 point, double rotateDegree, double arrowheadLength, double totalLength)
        {
            //
            double pi = Math.PI;
            double angle = 29;
            Vector2 t1 = fun.Polar(point, (angle / 2 + rotateDegree) * pi / 180, arrowheadLength / Math.Cos(angle / 2 * pi / 180));
            Vector2 t2 = fun.Polar(point, (rotateDegree - angle / 2) * pi / 180, arrowheadLength / Math.Cos(angle / 2 * pi / 180));
            Solid arrowhead = new Solid(point, t1, t2)
            {
                Layer = Layer.Default,
                Linetype = Linetype.ByBlock,
                Color = AciColor.ByBlock,
                Lineweight = Lineweight.ByBlock
            };
            Vector2 t1_2 = fun.Polar(point, rotateDegree * pi / 180, arrowheadLength);
            Vector2 tail = fun.Polar(point, rotateDegree * pi / 180, totalLength);
            Solid line = new Solid(t1_2, tail, tail);
            return new Solid[] { arrowhead, line };
        }
        //存在刃倾角时,刀片在俯视图上的投影（x轴坐标改变）,以刀尖所在点所在线旋转.
        public static void ContourWithLambdas(LwPolyline insertContour, double lambdas)
        {
            //刀尖所在点的x坐标
            lambdas = lambdas * Math.PI / 180;
            double x = insertContour.Vertexes[0].Position.X;
            int num = insertContour.Vertexes.Count;
            for (int i = 1; i < num; i++)
            {
                insertContour.Vertexes[i].Position = new Vector2((insertContour.Vertexes[i].Position.X - x) * Math.Tan(lambdas) + x,
                    insertContour.Vertexes[i].Position.Y);
            }
        }
        //画正三角形，可用于T型刀片,刀尖位置i1,边长l3，是否侧切flag，与切削方向夹角pAgl
        public static Vector2[] TrianglePoints(Vector2 i1, double l3, bool flag, double pAgl)
        {
            double pi = Math.PI;
            double agl_i1_i2 = 0;
            if (flag)
                agl_i1_i2 = pAgl - pi / 2;
            else
                agl_i1_i2 = pi - pAgl - pi / 3;
            Vector2 i2 = fun.Polar(i1, agl_i1_i2, l3);
            double agl_i2_i3 = agl_i1_i2 + pi - pi / 3;
            Vector2 i3 = fun.Polar(i2, agl_i2_i3, l3);
            return new Vector2[] { i1, i2, i3 };
        }
        //画菱形，可用于C型刀片,通过刀尖位置i4确定，l3表示边长，insertAngle表示刀尖夹角.flag为真-侧切，flag为假-端切，pagl是切刃与切削方向夹角
        //侧切时，i4-i1为切削刃，端切时i3-i4为切削刃
        public static Vector2[] DiamondPoints(Vector2 i4, double l3, double insertAngle, bool flag, double pAgl)
        {
            double agl_i4_i1 = 0;
            if (flag)
                agl_i4_i1 = pAgl - Math.PI / 2;
            else
                agl_i4_i1 = Math.PI - pAgl - insertAngle;
            //Console.Write(agl_i4_i1 * 180 / Math.PI);
            //Console.ReadKey();
            Vector2 i1 = fun.Polar(i4, agl_i4_i1, l3);
            double agl_i1_i2 = agl_i4_i1 + insertAngle;
            Vector2 i2 = fun.Polar(i1, agl_i1_i2, l3);
            double agl_i2_i3 = agl_i1_i2 + Math.PI - insertAngle;
            Vector2 i3 = fun.Polar(i2, agl_i2_i3, l3);
            return new Vector2[] { i4, i1, i2, i3 };
        }
        //闭合多段线向内偏移后的各点
        public static Vector2[] OffsetPoints(double offset, params Vector2[] points)
        {
            int num = points.Length;
            Vector2[] after = new Vector2[num];
            Vector2 p0;
            Vector2 p1;
            Vector2 p2;
            for (int i = 0; i < num; i++)
            {
                if (i == 0)
                    p0 = points[num - 1];
                else
                    p0 = points[i - 1];
                p1 = points[i];
                if (i == num - 1)
                    p2 = points[0];
                else
                    p2 = points[i + 1];
                double half_angle = ThreePointsAngle(p0, p1, p2) / 2;
                double agl_p1_p2 = Vector2.Angle(p1, p2);
                double dis = offset / Math.Sin(half_angle);
                after[i] = fun.Polar(p1, half_angle + agl_p1_p2, dis);
            }
            return after;
        }
        public static Vector2[] OffsetPoints(LwPolyline polyline, double offset)
        {
            List<LwPolylineVertex> vertices = polyline.Vertexes;
            int num = vertices.Count;
            Vector2[] points = new Vector2[num];
            for (int i = 0; i < num; i++)
            {
                points[i] = vertices[i].Position;
            }
            return OffsetPoints(offset, points);
        }
        //从多段线中拿到第n个圆弧,从1开始
        public static Arc GetArcFromPline(LwPolyline polyline, int num)
        {
            if (num <= 0)
                throw new Exception("参数应该为正整数");
            List<EntityObject> curves = polyline.Explode();
            int count = curves.Count;
            int k = 0;
            for (int i = 0; i < count; i++)
            {
                if (curves[i].Type.ToString() == "Arc")
                    k++;
                if (k == num)
                    return (Arc)curves[i];
            }
            throw new Exception("共找到" + k + "个圆弧对象，" + "未找逆时针方向到第" + num + "个圆弧");
        }
        //给多段线中的某个圆弧标注,不包含标注内容与位置,theArc表示第几个圆弧，从1开始，按多段线顺序计数。
        public static RadialDimension ReDimension(LwPolyline polyline, int theArc, DimensionStyle dimensionStyle)
        {
            if (theArc <= 0)
                throw new Exception("指定的圆弧从1开始，应当为正整数。");
            List<EntityObject> curves = polyline.Explode();
            int num = curves.Count;
            Arc[] arcs = new Arc[num];
            //找到了几个圆弧
            int how_many_Arc_found = 0;
            int i = 0;
            for (; i < num; i++)
            {
                if (curves[i].Type.ToString() == "Arc")
                {
                    arcs[i] = (Arc)curves[i];
                    how_many_Arc_found++;
                }
                if (how_many_Arc_found == theArc)
                    break;
            }
            if (how_many_Arc_found == 0)
                throw new Exception("多段线中未发现圆弧！");
            else
                return new RadialDimension(arcs[i], 0, 7, dimensionStyle);
        }
        //三点依次序画出的角，返回弧度
        public static double ThreePointsAngle(params Vector2[] vectors)
        {
            if (vectors.Length != 3)
                throw new Exception("参数是！！！三个！！！点");
            if (IsColline(vectors))
            {
                if (Vector2.Angle(vectors[0], vectors[1]) == Vector2.Angle(vectors[1], vectors[2]))
                    return Math.PI;
                else
                    return 0;
            }
            double a = Vector2.Distance(vectors[0], vectors[1]);
            double b = Vector2.Distance(vectors[1], vectors[2]);
            double c = Vector2.Distance(vectors[2], vectors[0]);
            //ab的夹角的余弦
            double cos_gamma = (Math.Pow(a, 2) + Math.Pow(b, 2) - Math.Pow(c, 2)) / (2 * a * b);
            return Math.Acos(cos_gamma);
        }
        //判断三点是否共线
        public static bool IsColline(params Vector2[] vectors)
        {
            if (vectors.Length != 3)
                throw new Exception("参数是！！！三个！！！点");
            Vector2 p0 = vectors[0];
            Vector2 p1 = vectors[1];
            Vector2 p2 = vectors[2];
            double k = (p0.Y - p1.Y) / (p0.X - p1.X);
            return p2.Y == k * (p2.X - p1.X) + p1.Y;
        }
        //把角变成圆弧
        public static LwPolyline AglToArc(LwPolyline polyline, int startIndex, double re, bool flag)
        {
            //原本的多段线有几个点
            List<LwPolylineVertex> verts = polyline.Vertexes;
            //原本的点的集合
            List<LwPolylineVertex> origin_vertices = new List<LwPolylineVertex>();
            foreach (LwPolylineVertex vertex in verts)
            {
                origin_vertices.Add(new LwPolylineVertex(vertex.Position.X, vertex.Position.Y));
            }
            int num = origin_vertices.Count;
            #region 求圆弧始末点
            //需要将startindex点(p1点)变成圆弧
            Vector2 p0;
            if (startIndex == 0)
                p0 = origin_vertices[num - 1].Position;
            else
                p0 = origin_vertices[startIndex - 1].Position;
            Vector2 p1 = origin_vertices[startIndex].Position;
            Vector2 p2;
            if (startIndex + 1 == num)
                p2 = origin_vertices[0].Position;
            else
                p2 = origin_vertices[startIndex + 1].Position;
            double half_agl = ThreePointsAngle(p0, p1, p2) / 2;
            double dis = re / Math.Tan(half_agl);
            //第一条线与x轴的夹角
            double firstLineAgl = Vector2.Angle(p1, p0);
            double secondLineAgl = Vector2.Angle(p1, p2);
            //圆弧首末两点
            Vector2 arcStart = fun.Polar(p1, firstLineAgl, dis);
            Vector2 arcEnd = fun.Polar(p1, secondLineAgl, dis);
            #endregion
            //去掉多段线中的startindex位的点（p1点），添加圆弧首末点
            polyline.Vertexes[startIndex].Position = arcStart;
            if (startIndex + 1 == num)
                polyline.Vertexes.Add(new LwPolylineVertex(arcEnd));
            else
            {
                polyline.Vertexes[startIndex + 1].Position = arcEnd;
                //多段线中从startindex+2以后的点均由对应的origin_vertices前一位填补
                for (int i = startIndex + 2; i < num; i++)
                {
                    polyline.Vertexes[i] = origin_vertices[i - 1];
                }
                //最后使用add添加最后一个点
                polyline.Vertexes.Add(origin_vertices[num - 1]);
            }
            //flag为真，逆时针画弧
            if (flag)
                polyline.Vertexes[startIndex].Bulge = Math.Tan((Math.PI - half_agl * 2) / 4);
            else
                polyline.Vertexes[startIndex].Bulge = Math.Tan(-(Math.PI - half_agl * 2) / 4);
            return polyline;
        }
        //三点按顺序构成一个角
        public static Arc AglToArc(double re, params Vector2[] points)
        {
            //判断是否共线
            if (IsColline(points))
                throw new Exception("三点共线!");
            Vector2 p0 = points[0];
            Vector2 p1 = points[1];
            Vector2 p2 = points[2];
            double half_agl = ThreePointsAngle(p0, p1, p2) / 2;
            double dis = re / Math.Tan(half_agl);
            double dis_p1_c = re / Math.Sin(half_agl);
            //第一条线与x轴的夹角
            double firstLineAgl = Vector2.Angle(p1, p0);
            double secondLineAgl = Vector2.Angle(p1, p2);
            Vector2 center = fun.Polar(p1, (firstLineAgl + secondLineAgl) / 2, dis_p1_c);
            //圆弧首末两点
            Vector2 arcStart = fun.Polar(p1, firstLineAgl, dis);
            Vector2 arcEnd = fun.Polar(p1, secondLineAgl, dis);
            //按角度构造弧
            double startAgl = Vector2.Angle(center, arcStart);
            double endAgl = Vector2.Angle(center, arcEnd);
            return new Arc(center, re, startAgl, endAgl);
        }
        //圆与直线的交点,当直线与x轴垂直时，数组中第一个是y值较小的那个,否则，数组中第一个是x值较小的那个。
        public static Vector2[] LineXCir(Arc arc, Vector2 p1, Vector2 p2)
        {
            double cx = arc.Center.X;
            double cy = arc.Center.Y;
            double r = arc.Radius;
            double a = 0;
            double b = 0;
            double c = 0;
            double delta = 0;
            double x1 = 0;
            double x2 = 0;
            double y1 = 0;
            double y2 = 0;
            //直线垂直x轴时
            if (p1.X == p2.X)
            {
                a = 1;
                b = -2 * cy;
                c = Math.Pow(cy, 2) + Math.Pow(p1.X - cx, 2) - Math.Pow(r, 2);
                delta = delta = Math.Pow(b, 2) - 4 * a * c;
                if (delta < 0)
                    return null;
                else if (delta > 0)
                {
                    //x1,x2
                    x1 = x2 = p1.X;
                    //y1,y2
                    y1 = (-b - Math.Sqrt(delta)) / (2 * a);
                    y2 = (-b + Math.Sqrt(delta)) / (2 * a);
                    return new Vector2[] { new Vector2(x1, y1), new Vector2(x2, y2) };
                }
                else
                    y1 = -b / (2 * a);
                Vector2 xy = new Vector2(p1.X, y1);
                //返回两个相同值的原因：调用时可以不管直线与圆有几个交点，只管取y轴值最大（小）的那个点。
                //需要判断是不是两个相同点，需自行判断两点的坐标。
                return new Vector2[] { xy, xy };
            }
            //直线不垂直x轴时,直线斜率k
            double k = (p1.Y - p2.Y) / (p1.X - p2.X);
            double t = -k * p1.X + p1.Y - cy;
            //求值
            a = 1 + Math.Pow(k, 2);
            b = 2 * (k * t - cx);
            c = Math.Pow(t, 2) + Math.Pow(cx, 2) - Math.Pow(r, 2);
            delta = Math.Pow(b, 2) - 4 * a * c;
            if (delta < 0)
                return null;
            else if (delta > 0)
            {
                //x1,x2
                x1 = (-b - Math.Sqrt(delta)) / (2 * a);
                x2 = (-b + Math.Sqrt(delta)) / (2 * a);
                //y1,y2
                y1 = k * (x1 - p1.X) + p1.Y;
                y2 = k * (x2 - p1.X) + p1.Y;
                return new Vector2[] { new Vector2(x1, y1), new Vector2(x2, y2) };
            }
            else
            {
                x1 = -b / (2 * a);
                y1 = k * (x1 - p1.X) + p1.Y;
                Vector2 lc1 = new Vector2(x1, y1);
                //返回两个相同值的原因：调用时可以不管直线与圆有几个交点，只管取x轴值最大（小）的那个点。
                //需要判断是不是两个相同点，需自行判断两点的坐标。
                return new Vector2[] { lc1, lc1 };
            }

        }
        public static Vector2[] LineXCir(Circle circle, Vector2 p1, Vector2 p2)
        {
            double cx = circle.Center.X;
            double cy = circle.Center.Y;
            double r = circle.Radius;
            double a = 0;
            double b = 0;
            double c = 0;
            double delta = 0;
            double x1 = 0;
            double x2 = 0;
            double y1 = 0;
            double y2 = 0;
            //直线垂直x轴时
            if (p1.X == p2.X)
            {
                a = 1;
                b = -2 * cy;
                c = Math.Pow(cy, 2) + Math.Pow(p1.X - cx, 2) - Math.Pow(r, 2);
                delta = delta = Math.Pow(b, 2) - 4 * a * c;
                if (delta < 0)
                    return null;
                else if (delta > 0)
                {
                    //x1,x2
                    x1 = x2 = p1.X;
                    //y1,y2
                    y1 = (-b - Math.Sqrt(delta)) / (2 * a);
                    y2 = (-b + Math.Sqrt(delta)) / (2 * a);
                    return new Vector2[] { new Vector2(x1, y1), new Vector2(x2, y2) };
                }
                else
                    y1 = -b / (2 * a);
                Vector2 xy = new Vector2(p1.X, y1);
                //返回两个相同值的原因：调用时可以不管直线与圆有几个交点，只管取y轴值最大（小）的那个点。
                //需要判断是不是两个相同点，需自行判断两点的坐标。
                return new Vector2[] { xy, xy };
            }
            //直线不垂直x轴时,直线斜率k
            double k = (p1.Y - p2.Y) / (p1.X - p2.X);
            double t = -k * p1.X + p1.Y - cy;
            //求值
            a = 1 + Math.Pow(k, 2);
            b = 2 * (k * t - cx);
            c = Math.Pow(t, 2) + Math.Pow(cx, 2) - Math.Pow(r, 2);
            delta = Math.Pow(b, 2) - 4 * a * c;
            if (delta < 0)
                return null;
            else if (delta > 0)
            {
                //x1,x2
                x1 = (-b - Math.Sqrt(delta)) / (2 * a);
                x2 = (-b + Math.Sqrt(delta)) / (2 * a);
                //y1,y2
                y1 = k * (x1 - p1.X) + p1.Y;
                y2 = k * (x2 - p1.X) + p1.Y;
                return new Vector2[] { new Vector2(x1, y1), new Vector2(x2, y2) };
            }
            else
            {
                x1 = -b / (2 * a);
                y1 = k * (x1 - p1.X) + p1.Y;
                Vector2 lc1 = new Vector2(x1, y1);
                //返回两个相同值的原因：调用时可以不管直线与圆有几个交点，只管取x轴值最大（小）的那个点。
                //需要判断是不是两个相同点，需自行判断两点的坐标。
                return new Vector2[] { lc1, lc1 };
            }

        }
        //圆弧与直线的交点
        public static List<Vector2> LineXArc(Arc arc, Vector2 p1, Vector2 p2)
        {
            double pi = Math.PI;
            Vector2[] results = LineXCir(arc, p1, p2);
            if (results == null)
                return null;
            double cx = arc.Center.X;
            double cy = arc.Center.Y;
            Vector2 center = new Vector2(cx, cy);
            double r = arc.Radius;
            List<Vector2> xpoints = new List<Vector2>();
            double startAgl = arc.StartAngle * pi / 180;//返回角度变弧度
            Vector2 startPoint = fun.Polar(center, startAgl, r);
            double endAgl = arc.EndAngle * pi / 180;//返回角度变弧度
            Vector2 endPoint = fun.Polar(center, endAgl, r);
            //由于返回的角度在0-360度之间，或者说在0-2*pi之间，可能存在归零的情况
            //即起点在0点之前，结束点在0点之后，起点270度，结束点270+91度，结束点会变成1度。
            double theAgl = ThreePointsAngle(startPoint, center, endPoint);
            if (startAgl + theAgl >= 2 * pi)
                endAgl = startAgl + theAgl;
            for (int i = 0; i < 2; i++)
            {
                double agl = Vector2.Angle(center, results[i]);
                Console.WriteLine("agl：" + agl);
                if (agl >= startAgl && agl <= endAgl)
                    xpoints.Add(results[i]);
            }
            //由于linexcir的返回结果未考虑两个交点是否是同一个点：
            //上诉判断过程结束后，若依然有两个点满足条件，需要判断这两个点是否是同一个点，若是，则删除集合中第二个
            if (xpoints.Count == 2)
            {
                if (xpoints[0].X == xpoints[1].X && xpoints[0].Y == xpoints[1].Y)
                    xpoints.Remove(xpoints[1]);
            }
            return xpoints;
        }
        #region 添加点到多段线方法
        //该方法将重复的添加多段线的点的过程封装，参数：多段线中点的数组或多个Vector2点，返回值：多段线。
        //仅适用于线段组成的多段线。
        public static LwPolyline AddPointsToLwPolyLine(params Vector2[] points)
        {
            LwPolyline hatchPline = new LwPolyline();
            for (int i = 0; i < points.Length; i++)
            {
                LwPolylineVertex point = new LwPolylineVertex(points[i]);
                hatchPline.Vertexes.Add(point);
            }
            return hatchPline;
        }
        //该方法只负责将点添加到曲线，不负责绘制非线段部分
        public static LwPolyline AddPointsToLwPolyLine(LwPolyline thePline, params Vector2[] points)
        {
            foreach (Vector2 point in points)
            {
                thePline.Vertexes.Add(new LwPolylineVertex(point));
            }
            return thePline;
        }
        #endregion
        //截取多段线的某一段上的点(折线)
        public static LwPolyline SubPline(LwPolyline thePline, int startIndex, int endIndex)
        {
            if (startIndex < 0)
                throw new Exception("起始点脚标不能小于零");
            if (startIndex >= endIndex)
                throw new Exception("按正确顺序截取折线");
            int theNum = thePline.Vertexes.Count;
            if (endIndex >= theNum)
                throw new Exception("脚标超出目标范围");
            LwPolyline oPline = new LwPolyline();
            List<LwPolylineVertex> vertexes = thePline.Vertexes;
            for (int i = startIndex; i <= endIndex; i++)
            {
                oPline.Vertexes.Add(vertexes[i]);
            }
            return oPline;
        }
        //两点画线段，主要用于画竖直线
        public static void DrawPlineByTwoPoints(DxfDocument dxf, Vector2 point1, Vector2 point2)
        {
            Vector2[] line = { point1, point2 };
            double width = 0.1;
            Layer layer = new Layer("contour") { Color = AciColor.Cyan };    //轮廓层
            fun.drawPlineOfw(dxf, line, width, layer);
        }
        public static void DrawPlineByTwoPoints(DxfDocument dxf, Vector2 point1, Vector2 point2, Layer layer)
        {
            Vector2[] line = { point1, point2 };
            double width = 0.1;
            fun.drawPlineOfw(dxf, line, width, layer);
        }
        //该方法用于计算上下切除点与中线的高度差，参数：缝隙宽度，中线所在圆的半径，缝隙中线在zy面与z轴的夹角
        //返回x0，较小值，上。x1，较大值，下。纬度较高的对应h较小.详见gap.SLDPRT文件
        public static double[] GetH(double gap, double r, double alpha)
        {
            if (alpha == 0)
                throw new Exception("角度为零时高度为gap/2");
            double r_sagitta = Math.Sqrt(Math.Pow(r, 2) - Math.Pow(gap / 2, 2));
            double sagitta = r - r_sagitta;
            double littleBow = Math.Sqrt(Math.Pow(sagitta, 2) + Math.Pow(gap / 2, 2));
            double a = 1 + 1 / Math.Pow(Math.Tan(alpha), 2);
            double b = -gap * Math.Cos(alpha) / Math.Pow(Math.Sin(alpha), 2);
            double c = Math.Pow(gap / Math.Sin(alpha), 2) / 4 - Math.Pow(littleBow, 2);
            double x0 = (-b - Math.Sqrt(Math.Pow(b, 2) - 4 * a * c)) / (2 * a);
            double x1 = (-b + Math.Sqrt(Math.Pow(b, 2) - 4 * a * c)) / (2 * a);
            return new double[] { x0, x1 };
        }
        //斜面上切除点的高度,第一个在下，第二个在上。详见gap1.SLDPRT
        public static double[] GetHofP(double gap, double dis, double alpha)
        {
            double[] height = new double[2];
            height[0] = (dis / Math.Tan(alpha) - gap / 2) * Math.Sin(alpha);
            height[1] = (dis / Math.Tan(alpha) + gap / 2) * Math.Sin(alpha);
            return height;
        }
        //绘制多段线的镜像线，仅支持对称轴平行x轴的情况
        public static LwPolyline MirrorPolyline(LwPolyline lwPolyline, Vector2 startpoint, Vector2 endpoint2)
        {
            List<LwPolylineVertex> points = lwPolyline.Vertexes;
            int num = points.Count;
            Vector2[] mpoints = new Vector2[num];
            for (int i = 0; i < num; i++)
            {
                Vector2 position = points[i].Position;
                mpoints[i] = new Vector2(position.X, 2 * startpoint.Y - position.Y);
            }
            LwPolyline mPline = AddPointsToLwPolyLine(mpoints);
            return mPline;
        }
        #region 填充线方法
        //添加剖面线,封闭曲线,仅支持直线与圆弧
        public static void HatchThePolyline(DxfDocument dxf, LwPolyline polyline, double pmxAngleDegree, double pmxdist)
        {
            if (!polyline.IsClosed)
                throw new Exception("非封闭曲线");
            if (pmxdist <= 0)
                throw new Exception("填充线间距错误");
            Layer hatching = new Layer("hatching") { Color = AciColor.Blue };    //填充层
            List<EntityObject> curves = polyline.Explode();
            int num = curves.Count;
            string[] typeName = new string[num];
            Line[] lines = new Line[num];
            Arc[] arcs = new Arc[num];
            for (int i = 0; i < num; i++)
            {
                typeName[i] = curves[i].Type.ToString();
                if (typeName[i] == "Line")
                {
                    lines[i] = (Line)curves[i];
                }
                else if (typeName[i] == "Arc")
                {
                    arcs[i] = (Arc)curves[i];
                }
            }
            fun.hatchsuboflineandarc(dxf, typeName, num, pmxAngleDegree, pmxdist, lines, arcs, hatching);
        }
        public static void HatchThePolyline(DxfDocument dxf, LwPolyline polyline)
        {
            HatchThePolyline(dxf, polyline, 45, 5);
        }
        public static List<EntityObject> ExplodeHatch(Hatch hatch, bool linkBoundary)
        {
            if (hatch == null)
                throw new ArgumentNullException(nameof(hatch));

            // Explode hatch to obtain its boundary entities.
            List<EntityObject> boundaryEntities = hatch.CreateBoundary(linkBoundary);
            return boundaryEntities;
        }
        #endregion
        #endregion
    }
}
